Class: PolarSSL::Cipher

Inherits:
Object
  • Object
show all
Defined in:
ext/polarssl/cipher.c

Overview

This class lets you encrypt and decrypt data.

Example

require 'polarssl'
require 'base64'

my_iv = SecureRandom.random_bytes(16)

cipher = PolarSSL::Cipher.new("AES-128-CTR")
cipher.set_iv(my_iv, 16)
cipher.setkey("mykey", 128, PolarSSL::Cipher::OPERATION_ENCRYPT)
cipher.update("secret stuff I want encrypted")
encrypted_data = cipher.finish()

encoded_encrypted_data = Base64.encode64(encrypted_data)
encoded_iv = Base64.encode64(my_iv)

puts encoded_encrypted_data
puts encoded_iv

When you get an exception

When using the Cipher class, you might get an exception. Some exeptions return a PolarSSL error code, like PolarSSL::Cipher::Error.

These error codes are directly passed on from the PolarSSL library and you can look up what they mean in the PolarSSL API documentation at: polarssl.org/api/.

Supported Cipher types:

CAMELLIA-128-CBC
CAMELLIA-192-CBC
CAMELLIA-256-CBC

CAMELLIA-128-CFB128
CAMELLIA-192-CFB128
CAMELLIA-256-CFB128

CAMELLIA-128-CTR
CAMELLIA-192-CTR
CAMELLIA-256-CTR

AES-128-CBC
AES-192-CBC
AES-256-CBC

AES-128-CFB128
AES-192-CFB128
AES-256-CFB128

AES-128-CTR
AES-192-CTR
AES-256-CTR

DES-CBC
DES-EDE-CBC
DES-EDE3-CBC

BLOWFISH-CBC
BLOWFISH-CFB64
BLOWFISH-CTR

NULL

Defined Under Namespace

Classes: BadInputData, Error, UnsupportedCipher