From: Robert Dober Date: 2008-09-06T18:47:12+09:00 Subject: Re: String sanitizing On Fri, Sep 5, 2008 at 10:13 PM, Travis Warlick wrote: > I have implemented a sanitize! method into the String class to properly > erase Strings from memory (example usage: clearing a password from memory), > but I want to make sure that what I'm doing is actually doing what I think > it is. > > Basically, is this code going to leave _anything_ lying around in memory > because of any undocumented/strange behavior or side effects of the []= > method? > > class String > def sanitize! > for i in 0...self.length > self[i] = 0 > end > self.delete!("\000") > end > end > > Also, feel free to recommend any "better" ways to do this. > > -- > Travis > > "You get it, hm? But it's not your head > that needs to understand!" > -- Hatsumi O'Sensei > > > Maybe 42.times do size.times do |i| self[i]=rand(256) end end This is a paranoiac approach and smaller values for 42 might do the trick. Actually I have no idea if disk memory or RAM is easier to reconstruct from magnetic residues. Cheers Robert -- C'est véritablement utile puisque c'est joli. Antoine de Saint Exupéry