Class: EzCrypto::Key

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

block_size block_size= calculate_key_size decode decrypt decrypt64 decrypt_file decrypt_with_password decrypter encode encrypt encrypt64 encrypt_file encrypt_with_password encrypter generate load marshal_dump marshal_load new on_decrypter on_encrypter store to_s with_password

### Attributes

algorithm | [R] |
raw | [R] |

### Public Class methods

block_size()

Return the block-size for IO-operations.

block_size=(size)

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

calculate_key_size(algorithm)

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

decode(encoded,options = {})

Initialize the key with Base64 encoded key data.

decrypt_with_password(password,salt,data,options = {})

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

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

encrypt_with_password(password,salt,data,options = {})

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

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

generate(options = {})

Generate random key.

load(filename)

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

new(raw,options = {})

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

with_password(password,salt,options = {})

Create key generated from the given password and salt

### Public Instance methods

decrypt(data)

Decrypts the data passed to it in binary format.

decrypt64(data)

Decrypts a Base64 formatted string

decrypt_file(src, tgt=nil, options = {} )

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

decrypter(target='')

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

encode()

returns the Base64 encoded key.

encrypt(data)

Encrypts the data and returns it in encrypted binary form.

encrypt64(data)

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

encrypt_file(src, tgt=nil, options = {} )

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

encrypter(target='')

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

marshal_dump()

Allows keys to be marshalled

marshal_load(s)

Allows keys to be unmarshalled

on_decrypter(target='', &block)

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

on_encrypter(target='', &block)

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

store(filename)

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.

to_s()

returns the Base64 encoded key. Synonym for encode.

[Validate]