Class: OpenSSL::Random

Inherits:
Object
  • Object
show all
Defined in:
lib/rb-gae-support/openssl.rb

Overview

Returns a string with a size number of secure random bytes

Class Method Summary collapse

Class Method Details

.random_bytes(size) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/rb-gae-support/openssl.rb', line 16

def self.random_bytes(size)
  # TODO - bounds check input, see how openssl does it.
  random = java.security.SecureRandom.new
  bytes = Java::byte[size].new
  random.nextBytes(bytes)
  String.from_java_bytes(bytes)
end