mirror of
https://github.com/ruby/ruby.git
synced 2025-09-16 17:14:01 +02:00
import OpenSSL from trunk
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@12496 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f5be4ddc8d
commit
18342ff8e0
48 changed files with 3828 additions and 365 deletions
|
@ -19,7 +19,7 @@
|
|||
#require 'openssl'
|
||||
|
||||
module OpenSSL
|
||||
module Cipher
|
||||
class Cipher
|
||||
%w(AES CAST5 BF DES IDEA RC2 RC4 RC5).each{|name|
|
||||
klass = Class.new(Cipher){
|
||||
define_method(:initialize){|*args|
|
||||
|
@ -41,18 +41,25 @@ module OpenSSL
|
|||
const_set("AES#{keylen}", klass)
|
||||
}
|
||||
|
||||
class Cipher
|
||||
def random_key
|
||||
str = OpenSSL::Random.random_bytes(self.key_len)
|
||||
self.key = str
|
||||
return str
|
||||
end
|
||||
# Generate, set, and return a random key.
|
||||
# You must call cipher.encrypt or cipher.decrypt before calling this method.
|
||||
def random_key
|
||||
str = OpenSSL::Random.random_bytes(self.key_len)
|
||||
self.key = str
|
||||
return str
|
||||
end
|
||||
|
||||
def random_iv
|
||||
str = OpenSSL::Random.random_bytes(self.iv_len)
|
||||
self.iv = str
|
||||
return str
|
||||
end
|
||||
# Generate, set, and return a random iv.
|
||||
# You must call cipher.encrypt or cipher.decrypt before calling this method.
|
||||
def random_iv
|
||||
str = OpenSSL::Random.random_bytes(self.iv_len)
|
||||
self.iv = str
|
||||
return str
|
||||
end
|
||||
|
||||
# This class is only provided for backwards compatibility. Use OpenSSL::Digest in the future.
|
||||
class Cipher < Cipher
|
||||
# add warning
|
||||
end
|
||||
end # Cipher
|
||||
end # OpenSSL
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue