在Objective-C中安全地生成随机数 [英] Generating Random Numbers Securely in Objective-C

查看:154
本文介绍了在Objective-C中安全地生成随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在哪里可以找到一个行业接受的安全伪随机数生成器的Objective-C?有没有一个内置的OS X SDK?

Where can I find an industry-accepted secure pseudo-random number generator for Objective-C? Is there one built in to the OS X SDK?

我的问题基本上与 this one ,但我正在寻找安全 PRNG。

My question is basically the same as this one, except that I'm looking for a secure PRNG.

编辑:

感谢大家的帮助。下面是一个简单的一行程序来实现/ dev / random方法:

Thanks everyone for the help. Here's a simple one-liner to implement the /dev/random method:

-(NSData *)getRandomBytes:(NSUInteger)length {
    return [[NSFileHandle fileHandleForReadingAtPath:@"/dev/random"] readDataOfLength:length];
}


推荐答案

Security.framework有一个设施为此,请调用 SecRandomCopyBytes()。虽然它基本上只是复制从 / dev / random

Security.framework has a facility for doing this, called SecRandomCopyBytes(). Although it's really basically just copying from /dev/random.

这篇关于在Objective-C中安全地生成随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆