Merge branch 'crypto-improvements'
This commit is contained in:
commit
c8d38d52a6
|
@ -82,7 +82,8 @@ sub encrypt {
|
||||||
eval {
|
eval {
|
||||||
$data =
|
$data =
|
||||||
encode_base64(
|
encode_base64(
|
||||||
$iv . $hmac . $self->_getCipher->set_iv($iv)->encrypt($data), '' );
|
$iv . $self->_getCipher->set_iv($iv)->encrypt( $hmac . $data ),
|
||||||
|
'' );
|
||||||
};
|
};
|
||||||
if ($@) {
|
if ($@) {
|
||||||
$msg = "Crypt::Rijndael error : $@";
|
$msg = "Crypt::Rijndael error : $@";
|
||||||
|
@ -108,14 +109,15 @@ sub decrypt {
|
||||||
$data = decode_base64($data);
|
$data = decode_base64($data);
|
||||||
my $iv;
|
my $iv;
|
||||||
$iv = bytes::substr( $data, 0, 16 );
|
$iv = bytes::substr( $data, 0, 16 );
|
||||||
my $hmac = bytes::substr( $data, 16, 16 );
|
$data = bytes::substr( $data, 16 );
|
||||||
$data = bytes::substr( $data, 32 );
|
|
||||||
eval { $data = $self->_getCipher->set_iv($iv)->decrypt($data); };
|
eval { $data = $self->_getCipher->set_iv($iv)->decrypt($data); };
|
||||||
|
|
||||||
if ($@) {
|
if ($@) {
|
||||||
$msg = "Crypt::Rijndael error : $@";
|
$msg = "Crypt::Rijndael error : $@";
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
my $hmac = bytes::substr( $data, 0, 16 );
|
||||||
|
$data = bytes::substr( $data, 16 );
|
||||||
if ( md5($data) ne $hmac ) {
|
if ( md5($data) ne $hmac ) {
|
||||||
$msg = "Bad MAC";
|
$msg = "Bad MAC";
|
||||||
return undef;
|
return undef;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user