Class EzCrypto::Key
In: lib/ezcrypto.rb
Parent: Object

The Key is the only class you need to understand for simple use.

Algorithms

The crypto algorithms default to aes-128-cbc however on any of the class methods you can change it to one of the standard openssl cipher names using the optional :algorithm=>alg name parameter.

Eg.

    Key.new @raw, :algorithm=>"des"
    Key.generate :algorithm=>"blowfish"
    Key.with_password @pwd,@salt,:algorithm=>"aes256"

License

ActiveCrypto and EzCrypto are released under the MIT license.

Support

To contact the author, send mail to pelleb@gmail.com

Also see my blogs at: stakeventures.com and neubia.com

This project was based on code used in my project StakeItOut, where you can securely share web services with your partners. stakeitout.com

(C) 2005 Pelle Braendgaard

Methods

Attributes

algorithm  [R] 
raw  [R] 

Public Class methods

Return the block-size for IO-operations.

Set the block-size for IO-operations (default: 512 bytes)

Given an algorithm this calculates the keysize. This is used by both the generate and with_password methods. This is not yet 100% complete.

Initialize the key with Base64 encoded key data.

Decrypts the data with the given password and a salt. Short hand for:

  key=Key.with_password(password,salt,options)
  key.decrypt(data)

Encrypts the data with the given password and a salt. Short hand for:

  key=Key.with_password(password,salt,options)
  key.encrypt(data)

Generate random key.

Load a key from a yaml_file generated via Key#store.

Initialize the key with raw unencoded binary key data. This needs to be at least 16 bytes long for the default aes-128 algorithm.

Create key generated from the given password and salt

Public Instance methods

Decrypts the data passed to it in binary format.

Decrypts a Base64 formatted string

Decrypt a file ‘inplace’ and remove a suffix see cipher_file IMPORTANT: The inputfile will be deleted by default.

Get a Decrypter object. You have to call final on it by yourself!

returns the Base64 encoded key.

Encrypts the data and returns it in encrypted binary form.

Encrypts the data and returns it in encrypted Base64 encoded form.

Encrypt a file ‘inplace’ and add a suffix see cipher_file. IMPORTANT: The inputfile will be deleted by default.

Get a Encrypter object. You have to call final on it by yourself!

Allows keys to be marshalled

Allows keys to be unmarshalled

Create a Decrypter object and yield it to a block. You must not call final by yourself, the method does this.

Create an Encrypter object and yield it to a block. You must not call final by yourself, the method does this.

Save the key data into a file, try to do this in a secure manner. NOTE: YAML::store & friends are not used to encance control over the generated file format.

returns the Base64 encoded key. Synonym for encode.

[Validate]