0

I am encrypting text in IONIC using @ionic-native/aes-256/ngx library and trying to decrypt the same in PHP but am unable to do so.

Here's the data :

Key : 12345678901234567890123456789012 (32bit) IV : 1234567890123456 Plain Text : ABCD 

Encrypted in IONIC : W2/PbR8z0sKBblfd4ezO1DKI/7UrB/egwDEGyw7w9tY=

It's decrypting in IONIC but not in PHP. In PHP I tried encryption of the same text using the same keys but also I am getting different encrypted data. PHP encrypted data for string ABCD : 5JvCGZhhM12hA9Tz/ldBvw==

Can somebody please explain if I am missing anything?

import { AES256 } from ‘@ionic-native/aes-256/ngx’; constructor(public aes:AES256){} encrypt(key, iv, data){ return this.aes.encrypt(key, iv, data); } 
output : "W2/PbR8z0sKBblfd4ezO1DKI/7UrB/egwDEGyw7w9tY= " 
$iv = “1234567890123456”; $key = “12345678901234567890123456789012”; $encrypted = "W2/PbR8z0sKBblfd4ezO1DKI/7UrB/egwDEGyw7w9tY= "; $decrypted = openssl_decrypt($encrypted, “AES-256-CBC”, $key, 0, $iv); echo $decrypted; 

Encrypted data in IONIC and PHP are different. I want to decrypt the text in PHP which was done using IONIC

4
  • 1
    @ionic-native/aes-256 references this repository with a TypeScript implementation of AES256, which in turn references this repository with an Android implementation of AES256. Commented Jun 23, 2024 at 14:12
  • 1
    This logic uses a key derivation, namely PBKDF2 with SHA-1, 1001 iterations and the static salt hY0wTq6xwc6ni01G. With this, the ciphertext can indeed be decrypted, namely as Base64 string: arqWj4Qs3nDX5iYw9blqyA==. An incorrect decryption is unlikely due to the valid padding with seven 0x07 bytes. Commented Jun 23, 2024 at 14:22
  • 1
    However, the result does not match the plaintext ABCD that you expect. So either your expectation is wrong or the result is possibly a second ciphertext whose decryption results in ABCD. Commented Jun 23, 2024 at 14:30
  • Using the given plaintext, algorithm, key, and iv the base64'd ciphertext output is: 5JvCGZhhM12hA9Tz/ldBvw== whose decoded length is 16 bytes. What you have give as an example ciphertext has a decoded length of 32 bytes. This implies to me that you are using a longer and therefore wholly different plaintext input for your Ionic test code, to say nothing of if the key and IV match. Commented Jun 24, 2024 at 1:30

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.