I am trying to encrypt text/string in vb.net, pass to php script and decrypt there using chilkat crypt2 library for both coding language.
it works fine for non Unicode text with default charset :)
but when i try to crypt and decrypt Unicode text using "utf-8" charset it does not work..
php failed to decrypt it properly :( but if i decrypt the same encrypted text using vb.net it works as it should..
Raw/Plain Text:
আস-সালামু-আলাইকুম ওয়া-রহমাতুল্লাহি ওয়া-বরকাতুহু
encrypted by vb.net function:
PQ7i4/4kvMKR64jD4Y8umQJAR9+vAuhZ+bbdtZ8NzBJpPtNtL6c42lR0I1LAdeecI+D3n111CQQffHbMXL1xaccFQR0fqztmJawAMBL3N/VA4Lt45nRmnqc72tKwl0V3Fgayiysm0YsMW6N7hPkI6rqRn2smo9Xc8LEb4kfP/B/HkWhFP70mCsM7t8DUN2Sj
here the code follows:
vb.net code:
Public Function fCryption(strRaw As String, bolEncrypt As Boolean, strPass As String) As String
Dim objCrypt As Chilkat.Crypt2
Dim bolCryptReturn As Boolean
Dim strHexKey As String
Dim strReturn As String
objCrypt = New Chilkat.Crypt2
bolCryptReturn = objCrypt.UnlockComponent("Here Your Own Key Goes")
objCrypt.Charset = "utf-8"
objCrypt.CryptAlgorithm = "aes"
objCrypt.CipherMode = "cbc"
objCrypt.KeyLength = 256
strHexKey = objCrypt.GenEncodedSecretKey(strPass, "hex")
objCrypt.SetEncodedKey(strHexKey, "hex")
objCrypt.EncodingMode = "base64"
If bolEncrypt = True Then
strReturn = objCrypt.EncryptStringENC(strRaw)
Else
strReturn = objCrypt.DecryptStringENC(strRaw)
End If
objCrypt.Dispose()
objCrypt = Nothing
Return strReturn
End Function
now the php function:
function fCryption($strRaw, $bolEncrypt, $strPass)
{
$objCrypt = new CkCrypt2();
$objCrypt->UnlockComponent('Here Your Own Key Goes');
$objCrypt->put_Charset('utf-8');
$objCrypt->put_CryptAlgorithm('aes');
$objCrypt->put_CipherMode('cbc');
$objCrypt->put_KeyLength(256);
$strHexKey = $objCrypt->genEncodedSecretKey($strPass, 'hex');
$objCrypt->SetEncodedKey($strHexKey, 'hex');
$objCrypt->put_EncodingMode('base64');
if($bolEncrypt == true)
{
$strReturn = $objCrypt->encryptStringENC($strRaw);
}
else
{
$strReturn = $objCrypt->decryptStringENC($strRaw);
}
unset($objCrypt);
return $strReturn;
}
and this is what php function return when i try to decrypt:
-- - -
so, i can't seems to find the cause why same function for same library works fine on vb.net but not on php :(
thanks in advance
best regards