decrypt issue
I have an application client side both in php and cf code which does simliar things. Both post to cf server 2021 upadate 18. i believe the update 18 is cuasing the issue but i would have to roll back to 17 to test this. In my logs everything was fine until 2/20/2025 and in my installer downloads on the CF server i see on 2/19 i downloaded update 18 so i assume it was intalled on the 19th or early on 20th of feb. Every since then I have the problem. I am not 100% certain that is the issue but if that makes sense to anyone let me know. Now for the issue. To be clear If i encrypt on a CF server which front end app is (also update 18) and then decrpt on 2nd CF server update 18th this still works even after update 18 installed on 2/20. My issue is with PHP front end. I am encrypting with php page and posting to cf server (same one as the cf front end app) and this now does not work. Both php and cf front end worked fine before update 18.
For Cf front end i am using basic: function encryptData(data) {
var encryptionKey = generateEncryptionKey();
var jsonData = serializeJSON(data);
var encryptedString = encrypt(jsonData, encryptionKey, "AES", "hex");
return encryptedString;
}
on backend to decypt i am using: function decryptData(encryptedString, accountID, secretKey) {
var encryptionKey = generateEncryptionKey(accountID, secretKey);
var decryptedJSON = decrypt(encryptedString, encryptionKey, "AES", "hex");
return deserializeJSON(decryptedJSON);
}
this seems to work. BUT if i send encryption using this function on php to encrypt: function encryptForReauthenticationWC($data, $client) {
try {
$keyBytes = base64_decode($client['encryption_key']);
$ivBytes = base64_decode($client['iv']);
// Ensure data is UTF-8 encoded
$dataBytes = mb_convert_encoding($data, 'UTF-8');
// Apply PKCS7 padding manually
$blockSize = 16;
$padSize = $blockSize - (strlen($dataBytes) % $blockSize);
$dataBytes .= str_repeat(chr($padSize), $padSize);
$encryptedBytes = openssl_encrypt($dataBytes, 'AES-256-CBC', $keyBytes, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $ivBytes);
$encryptedData = customUrlEncode($encryptedBytes);
logMessage_check("Custom encoded data length: " . strlen($encryptedData), $client);
return $encryptedData;
} catch (Exception $e) {
logMessage_check("Encryption failed: " . $e->getMessage(), $client);
return "";
}
}
the decryption fails i have a failver on the backend if the normal decrypt data function does not work to try this way: <cfif NOT isDecrypted>
<cftry>
<!--- Decode the custom encoded data --->
<cfset customEncodedData = url.data>
<cfset base64EncodedData = replace(replace(replace(customEncodedData, '-', '+', 'all'), '_', '/', 'all'), ',', '=', 'all')>
<cfset encryptedBytes = binaryDecode(base64EncodedData, "base64")>
<!--- Log received data info --->
<cflog file="check_api_auth_log" text="Received data length: #len(customEncodedData)#" type="information">
<cflog file="check_api_auth_log" text="Decoded data length: #arrayLen(encryptedBytes)#" type="information">
<!--- Decode the Base64 encryption key and IV --->
<cfset keyBytes = binaryDecode(clientDetails.encryption_key, "base64")>
<cfset ivBytes = binaryDecode(clientDetails.iv, "base64")>
<!--- Create SecretKeySpec and IvParameterSpec --->
<cfset secretKeySpec = createObject("java", "javax.crypto.spec.SecretKeySpec").init(keyBytes, "AES")>
<cfset ivParameterSpec = createObject("java", "javax.crypto.spec.IvParameterSpec").init(ivBytes)>
<!--- Create Cipher instance --->
<cfset cipher = createObject("java", "javax.crypto.Cipher").getInstance("AES/CBC/PKCS7Padding")>
<!--- Initialize cipher for decryption --->
<cfset cipher.init(cipher.DECRYPT_MODE, secretKeySpec, ivParameterSpec)>
<cfset decryptedBytes = cipher.doFinal(encryptedBytes)>
<cfset decryptedString = toString(decryptedBytes, "UTF-8")>
<!--- Log decrypted data info --->
<cflog file="check_api_auth_log" text="Decrypted data length: #len(decryptedString)#" type="information">
<!-- Parse the decrypted string into a struct -->
<cfset decryptedParts = listToArray(decryptedString, "|")>
<cfset decryptedData = {
userID: decryptedParts[1],
timestamp: decryptedParts[2]
}>
<cfset isDecrypted = true>
<cfcatch>
<cflog file="check_api_auth_log" text="Error: WC re-authentication decryption failed. Error: #cfcatch.message#" type="error">
<cfoutput>Error: Invalid verification data.</cfoutput>
<cfabort>
</cfcatch>
</cftry>
</cfif>
In my logs for the php attempt the log error i am seeing is Error: cannot fine any provider supporting AES/CBC/PKCS7Padding
neither work and it completely fails. AGain all worked before update 18 I can try to roll back unless someone can see something obvious but of course I would like to solve it becuase it all worked before update 18 and i need to upate at some point. Thanks in advance
