Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
568 views
in Technique[技术] by (71.8m points)

objective c - Securely zero out memory in NSString

On iOS, I was wondering, say if I read user provided password value as such:

NSString* strPwd = UITextField.text;

//Check 'strPwd'
...

//How to clear out 'strPwd' from RAM?

I just don't like leaving sensitive data "dangling" in the RAM. Any idea how to zero it out?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Basically you really can't. There are bugs filed with Apple over this exact issue. Additionally there are problems with UITextField and NSString at a minimum.

To reiterate the comment in a now deleted answer by @Leo Natan:

Releasing the enclosing NSString object does not guarantee the string bytes are zeroes in memory. Also, if a device is jailbroken, all the sandboxing Apple promises will be of no use. However, in this case, there is little one can do, as it is possible to swap the entire runtime in the middle of the application running, this getting the password from the memory.

Please file another bug with apple requesting this, the more the better.

Apple Bug Reporter


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...