It is probably a good idea to add that if you want Crypt::Mode::CBC to be backwards compatible with Crypt::CBC if header is set to none or randomiv and literal_key is not set.
my $keysize = Crypt::Cipher->keysize($name);
$key = Digest::MD5::md5($key);
while (length($key) < $keysize) {
$key .= Digest::MD5::md5($key);
}
$key = substr($key,0,$keysize);
As for decrypting with header salt
my ($salt) = $text =~/^Salted__(.{8})/s;
substr($text,0,16) = '';
($key,$iv) = _salted_key_and_iv($key,$salt);
sub _salted_key_and_iv {
my ($key,$salt) = @_;
my $key_len = Crypt::Cipher->keysize('AES');
my $iv_len = Crypt::Cipher->blocksize('AES');
my $desired_len = $key_len+$iv_len;
my $data = '';
my $d = '';
while (length $data < $desired_len) {
$d = Digest::MD5::md5($d . $key . $salt);
$data .= $d;
}
return (substr($data,0,$key_len),substr($data,$key_len,$iv_len));
}
It is probably a good idea to add that if you want Crypt::Mode::CBC to be backwards compatible with Crypt::CBC if header is set to none or randomiv and literal_key is not set.
As for decrypting with header salt