AES-256-CTR Decryption Concern with `react-native-aes-crypto` on iOS

AES-256-CTR Decryption Concern with `react-native-aes-crypto` on iOS


Clarification.

I’m dealing with a difficulty with AES-256-CTR decryption utilizing the react-native-aes-crypto library. The decryption works completely on Android however fails on iOS with the error [Error: Decrypt failed].

Beneath is the decryption code:

import Aes from 'react-native-aes-crypto';

export async perform decryptAES_256_CTR(content material, key, iv) { 
   const hexIV = base64ToHex(iv);
   const hexKey = base64ToHex(key);

   // Log transformed values
   console.log('Cipher (Base64):', content material);
   console.log('Key (Hex):', hexKey);
   console.log('IV (Hex):', hexIV);

   // Decrypt utilizing AES
   return await Aes.decrypt(content material, hexKey, hexIV, 'aes-256-ctr');
}

perform base64ToHex(base64) {
  const uncooked = Buffer.from(base64, 'base64').toString('binary');
  let outcome="";
  for (let i = 0; i < uncooked.size; i++) {
    const hex = uncooked.charCodeAt(i).toString(16);
    outcome += hex.size === 2 ? hex : '0' + hex;
  }
  return outcome.toUpperCase();
}

Downside Description

  • The decryption works nicely on Android however fails on iOS.
  • The exception thrown on iOS:
(NOBRIDGE) ERROR  Error throughout decryption: [Error: Decrypt failed]

Logs

Listed here are the logged inputs when the error happens:

Cipher (Base64): /j2YKMCrAsi00nN9lnshKwmIuHSHFteafgS0uWskhr0aw0152WPZPKKmNQthurxOO0rtHl8F84hlVg8YsqTAZ5enGKNk+XLKUi58c8H7rQO/Dedw8W3Pv6iHrZN/hLTBo1T4V8XP5sC+FP7NxHvTXrL8lfQ/dhWPYqZZ8hae12/Pwa1dNgL4B0hQaV0AdQySix9zRwCqrVUJXdoJizBcf3gvKl6+goMg5+KYLP+xJUSPCMiz01ocL2x2tipLxVo9FUjgnR2nj+OlTrZ99sWPTD8JkzRL77ge6G/wbCyzIU//JbR1Q+FfFCE+GcphMReH5dNiTR5g2XSeZo/GiVz+n+62xXMVySAs/0DJt4P62mnvE6LUkkAY/02wzvVb4jzuMP/R5KL2oZjuqPIfVvRrw/vp1Wj5/KwWKg6sBb0/z28StBn1qB5is/J61orO8yam2DowYFIZE+vZY3TCIlmoaFEviVW52yVWWGnWwa9AVxUYXUH4ZlbhBdGbO9+xrRhtx9RiU5cahMDOen/k2upiej7kBpXyPisPhPPQ1+K9no1D7/HBnawf+cs5UbOi28PmiS0h07nQd86dhKECFKOWzSaY1VNC0iAXRrG3BEzTzxgEjJmt/LCyl6YI+XpYX5BEXPq94hNYPgrhfVdK+uesnGsLT1XegIryzQzUWSoITpX9R8TwoO13HS0wv8Nu26Iuw3CJvbsGSEbG0glY4HRHwvwuSGIwvLo4Cc6QVCIqGhiSUITwMfd4KbCmLcO87qMc1fvyeeEE91A/3kNGY1AqubnJBqVu6eA2oxp3xdJ8HDKm8w1m0qF3sc/QZD/SnWPoaFBcAPV0mW0KG6XvyZpe9+CJUN4vPeoYs2iSYEkiy+n3L/yFo6tZIgvECQ856sjVjozTecEcyZhKPbpAfiKfWaub+VqcnoeAHLSpblnOGnaK7vtBGmzyfVw++Y0NrNhgSIO+IML+13puoxafVtb/aQ3t4+5Ey1n8Qw6ni9a/GJf0Ix7DK404mo7Bkb+YFJKeuOhb49QhMLzUGbeq5ieBAToiHH4Uz2j6Xrbmolp89Wa36EiVjAfkC15S9bEZWUm+H82cchfFwoHee/hmlzVfdzwDS6WQWyARxaBE048uESnFBAbA5PROobEXob73Q7rePWK4sCLY5P3Q/zTHQ0iF0xht7Bvlq7XnpjUqKjBL6cXqbW15gBDgvmIdZKUFCxfuWqaP4eRWVMwo++cq/P+ScIYELI0aHNJ7RfT9vWbElndQm1IgYQak56FiZ7ATp/MBii3xudE5UJ+wyNAvh58ye3DUoNT2SPfp+nA6JzTO7nAM6I3Kr79f3bIDfx2LP11xnYU4nyTE5LM0o7EpluG6sdIPcf4XpljKXxinJ5Dzb3P+kcyZm/ENmHnqyaH3pQT9
Key (Hex): 6B76F4CE1907991A845AB7523F8C1834E658CBF63A0214A589A2F4752BD19977
IV (Hex): 6333AFCC5354A014

Steps to Reproduce

  1. Use the decryptAES_256_CTR perform on each Android and iOS.
  2. Move the identical ciphertext, key, and IV.
  3. Observe the failure on iOS.

Troubleshooting Performed

  1. Verified the important thing size (32 bytes for AES-256) and IV size (16 bytes).
  2. Checked that the ciphertext is in Base64 format.
  3. Ensured the library is correctly linked utilizing pod set up.
  4. Examined with completely different keys and ciphertexts.

Questions

  1. Are there any identified points with AES-256-CTR decryption utilizing react-native-aes-crypto on iOS?
  2. Might this be attributable to variations in how the library handles decryption between platforms?
  3. Is there a selected configuration required for AES-256-CTR on iOS?

Any assist or options could be significantly appreciated!

author avatar
roosho Senior Engineer (Technical Services)
I am Rakib Raihan RooSho, Jack of all IT Trades. You got it right. Good for nothing. I try a lot of things and fail more than that. That's how I learn. Whenever I succeed, I note that in my cookbook. Eventually, that became my blog. 
rooshohttps://www.roosho.com
I am Rakib Raihan RooSho, Jack of all IT Trades. You got it right. Good for nothing. I try a lot of things and fail more than that. That's how I learn. Whenever I succeed, I note that in my cookbook. Eventually, that became my blog. 

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here


Latest Articles

author avatar
roosho Senior Engineer (Technical Services)
I am Rakib Raihan RooSho, Jack of all IT Trades. You got it right. Good for nothing. I try a lot of things and fail more than that. That's how I learn. Whenever I succeed, I note that in my cookbook. Eventually, that became my blog.