Sha256: f1957d3da93a394b50a443f4a450852dfbaa972c38efb1bbefd5da0ef985464d

Contents?: true

Size: 1.26 KB

Versions: 44

Compression:

Stored size: 1.26 KB

Contents

=begin
= $RCSfile: cipher.rb,v $ -- Ruby-space predefined Cipher subclasses

= Info
  'OpenSSL for Ruby 2' project
  Copyright (C) 2002  Michal Rokos <m.rokos@sh.cvut.cz>
  All rights reserved.

= Licence
  This program is licenced under the same licence as Ruby.
  (See the file 'LICENCE'.)

= Version
  $Id: cipher.rb,v 1.1.2.2 2006/06/20 11:18:15 gotoyuzo Exp $
=end

require 'openssl'

module OpenSSL
  module Cipher
    class Cipher
      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
    end
    
    %w(AES CAST5 BF DES IDEA RC2 RC4 RC5).each{|name|
      klass = Class.new(Cipher){
        define_method(:initialize){|*args|
          cipher_name = args.inject(name){|n, arg| "#{n}-#{arg}" }
          super(cipher_name)
        }
      }
      const_set(name, klass)
    }

    %w(128 192 256).each{|keylen|
      klass = Class.new(Cipher){
        define_method(:initialize){|mode|
          mode ||= "CBC"
          cipher_name = "AES-#{keylen}-#{mode}"
          super(cipher_name)
        }
      }
      const_set("AES#{keylen}", klass)
    }
  end # Cipher
end # OpenSSL

Version data entries

44 entries across 44 versions & 4 rubygems

Version Path
redcar-dev-0.12.1dev-java lib/openssl/lib/openssl/cipher.rb
redcar-dev-0.12.0dev-java lib/openssl/lib/openssl/cipher.rb
redcar-0.11 lib/openssl/lib/openssl/cipher.rb
redcar-0.11.0dev lib/openssl/lib/openssl/cipher.rb
redcar-0.10 lib/openssl/lib/openssl/cipher.rb
redcar-0.9.2 lib/openssl/lib/openssl/cipher.rb
redcar-0.9.1 lib/openssl/lib/openssl/cipher.rb
redcar-0.9.0 lib/openssl/lib/openssl/cipher.rb
redcar-0.8.1 lib/openssl/lib/openssl/cipher.rb
redcar-0.8 lib/openssl/lib/openssl/cipher.rb
redcar-0.7 lib/openssl/lib/openssl/cipher.rb
redcar-0.6.1 lib/openssl/lib/openssl/cipher.rb
redcar-0.6 lib/openssl/lib/openssl/cipher.rb
redcar-0.6.1dev lib/openssl/lib/openssl/cipher.rb
redcar-0.5.1 lib/openssl/lib/openssl/cipher.rb
redcar-0.5 lib/openssl/lib/openssl/cipher.rb
redcar-0.5.6dev lib/openssl/lib/openssl/cipher.rb
redcar-0.5.5dev lib/openssl/lib/openssl/cipher.rb
redcar-0.5.4dev lib/openssl/lib/openssl/cipher.rb
redcar-0.5.3dev lib/openssl/lib/openssl/cipher.rb