本文简要介绍ruby语言中 SecureRandom模块
的用法。
安全的随机数生成器接口。
该库是一个保护随机数生成器的接口,适用于在 HTTP cookie 等中生成会话 key 。
您可以通过要求在您的应用程序中使用此库:
require 'securerandom'
它支持以下安全随机数生成器:
-
openssl
-
/dev/urandom
SecureRandom
由 Random::Formatter
模块扩展,该模块定义了以下方法:
-
alphanumeric
-
base64
-
choose
-
hex
-
rand
-
random_bytes
-
random_number
-
urlsafe_base64
-
uuid
这些方法可用作 SecureRandom
的类方法,例如SecureRandom.hex
。
如果安全随机数生成器不可用,则会引发 NotImplementedError
。
相关用法
- Ruby Security模块用法及代码示例
- Ruby Set flatten()用法及代码示例
- Ruby Set.replace用法及代码示例
- Ruby Set intersection()用法及代码示例
- Ruby Set类用法及代码示例
- Ruby Set.==用法及代码示例
- Ruby Set.disjoint?用法及代码示例
- Ruby Set size()用法及代码示例
- Ruby Set compare_by_identity?用法及代码示例
- Ruby Set merge()用法及代码示例
- Ruby Set.classify用法及代码示例
- Ruby Set add?用法及代码示例
- Ruby Set compare_by_identity()用法及代码示例
- Ruby Set flatten!()用法及代码示例
- Ruby Set divide()用法及代码示例
- Ruby Set replace()用法及代码示例
- Ruby Set.[]用法及代码示例
- Ruby Set.===用法及代码示例
- Ruby Set include?()用法及代码示例
- Ruby Set subtract()用法及代码示例
- Ruby Set member?()用法及代码示例
- Ruby Set intersect?()用法及代码示例
- Ruby Set proper_subset?()用法及代码示例
- Ruby Set difference()用法及代码示例
- Ruby Set.-用法及代码示例
注:本文由纯净天空筛选整理自ruby-lang.org大神的英文原创作品 SecureRandom模块。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。