# man > Crypt::Cipher

---
type: CommandReference
command: Crypt::Cipher
mode: perldoc
section: 3pm
source: perldoc
---

## Quick Reference
- `use Crypt::Cipher;` — Load the module
- `$c = Crypt::Cipher->new('AES', $key)` — Create a cipher object
- `$ciphertext = $c->encrypt($plaintext)` — Encrypt a single block
- `$plaintext = $c->decrypt($ciphertext)` — Decrypt a single block
- `$c->blocksize` — Get block size (bytes)
- `$c->max_keysize` — Get maximal key size (bytes)
- `Crypt::Cipher->max_keysize('AES')` — Get key size as a class method
- `$c->default_rounds` — Get default rounds (where applicable)

## Name
Generic interface to cipher functions

## Synopsis
perl
use Crypt::Cipher;

my $c = Crypt::Cipher->new($algorithm, $key [, $rounds]);
my $ciphertext = $c->encrypt($plaintext);
my $plaintext = $c->decrypt($ciphertext);
my $blocksize = $c->blocksize;
my $max_key  = $c->max_keysize;
# Class method variants: Crypt::Cipher->max_keysize('AES'), etc.
**Important:** This module provides only elementary single-block encryption/decryption. To process arbitrary-length data, use a block cipher mode such as [Crypt::Mode::CBC](http://localhost/phpMan.php/perldoc/Crypt%3A%3AMode%3A%3ACBC/markdown), [Crypt::Mode::CTR](http://localhost/phpMan.php/perldoc/Crypt%3A%3AMode%3A%3ACTR/markdown), or [Crypt::CBC](http://localhost/phpMan.php/perldoc/Crypt%3A%3ACBC/markdown).

## Methods
- `new($name, $key [, $rounds])` — Constructor. `$name` is one of: AES, Anubis, Blowfish, CAST5, Camellia, DES, DES_EDE, KASUMI, Khazad, MULTI2, Noekeon, RC2, RC5, RC6, SAFERP, SAFER_K128, SAFER_K64, SAFER_SK128, SAFER_SK64, SEED, Skipjack, Twofish, XTEA, IDEA, Serpent (any `Crypt::Cipher::<NAME>`). For ciphers supporting configurable rounds (e.g., MULTI2, RC5, SAFER), the optional `$rounds` argument sets the number of rounds.
- `encrypt($plaintext)` — Encrypts one block of **blocksize** bytes; returns ciphertext.
- `decrypt($ciphertext)` — Decrypts one block of **blocksize** bytes; returns plaintext.
- `keysize` — Alias for `max_keysize` (provided for compatibility with [Crypt::CBC](http://localhost/phpMan.php/perldoc/Crypt%3A%3ACBC/markdown)).
- `max_keysize` — Returns the maximal allowed key size (bytes). Can be called on an instance or as a class method: `Crypt::Cipher->max_keysize('AES')`.
- `min_keysize` — Returns the minimal allowed key size (bytes). Instance or class method.
- `blocksize` — Returns the block size (bytes). Instance or class method.
- `default_rounds` — Returns the default number of rounds for ciphers that support round configuration. Instance or class method.

## Examples
perl
# Example 1: Single-block encryption
use Crypt::Cipher;
my $key = '...';   # length must be valid for the cipher
my $c = Crypt::Cipher->new('AES', $key);
my $ciphertext = $c->encrypt('plain text block');
my $plaintext  = $c->decrypt($ciphertext);
perl
# Example 2: Using CBC mode via Crypt::Mode::CBC
use Crypt::Mode::CBC;
my $key = '...';
my $iv  = '...';   # 16 bytes
my $cbc = Crypt::Mode::CBC->new('AES');
my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
perl
# Example 3: Compatibility with Crypt::CBC
use Crypt::CBC;
use Crypt::Cipher;
my $key = '...';
my $iv  = '...';
my $cipher = Crypt::Cipher('AES', $key);
my $cbc = Crypt::CBC->new( -cipher => $cipher, -iv => $iv );
my $ciphertext = $cbc->encrypt("secret data");
## See Also
- [CryptX](http://localhost/phpMan.php/perldoc/CryptX)
- [Crypt::Mode::CBC](http://localhost/phpMan.php/perldoc/Crypt%3A%3AMode%3A%3ACBC/markdown)
- [Crypt::Mode::CTR](http://localhost/phpMan.php/perldoc/Crypt%3A%3AMode%3A%3ACTR/markdown)
- [Crypt::CBC](http://localhost/phpMan.php/perldoc/Crypt%3A%3ACBC/markdown)
- Subclass modules: [Crypt::Cipher::AES](http://localhost/phpMan.php/perldoc/Crypt%3A%3ACipher%3A%3AAES/markdown), [Crypt::Cipher::Blowfish](http://localhost/phpMan.php/perldoc/Crypt%3A%3ACipher%3A%3ABlowfish/markdown), etc.