Hi am trying to check the compatability of encryption done on BE.
BE provided the below code `
$secret_key = VALUE1`;
$secret_iv = VALUE2;
$encrypt_method = "AES-256-CBC";
$key = hash('sha256', $secret_key);
$iv = substr(hash('sha256', $secret_iv), 0, 16);
openssl_encrypt($string, $encrypt_method, $key, 0, $iv)`
the openssl gave SNtvZ3Dpv1S88Ha6aVBdcg== when input string is abc
I tried few alogritham but I wasnt able to correctly match it with BE
he $key and $iv value I generated same as BE. but when it comes to encryption it doesnt give any result or saying Expected IV length is 16 but got 8
The following are the packages I tried
- import Aes from 'react-native-aes-crypto';
Aes.encrypt(inputText, hash, _IV, 'aes-256-cbc').then(cipher => {
console.log('cipher', cipher); });
This throws an error Error: expected IV length of 16 but was 8 I checked the length of _IV and it is certanly 16
- import CryptoAesCbc from 'react-native-crypto-aes-cbc';
CryptoAesCbc.encryptInBase64(
base64.encode(ivHash.substr(0, 16)),
base64.encode(hash),
'abc',
'128',
)
.then(encryptString => {
console.log('encryptString', encryptString);
})
.catch(error => {
console.log('error ', error);
});
This the encryptString value prints empty string
Please someone give me some insight into this.
FYI am checking in Android for the time being
EDIT 1
I red in some post about converting to _IV to hex
so I did this
Aes.encrypt(
inputText,
hash,
Buffer.from(_IV).toString('hex'),
'aes-256-cbc',
)
.then(cipherText => console.log('cipherText', cipherText))
.catch(error => console.log('error here', error));
It gave me wrong out out cipherText: yLvY847qCMHHGHdachjKGw==
Any help is appreciated
Thanks in advance