簡體   English   中英

使用加密進行加密和解密

[英]Encryption and Decryption using Crypto

我需要在iOS和Android上加密數據,並使用Crypto在Node中解密數據。

我正在嘗試在Android和iOS中加密數據,並在NodeJs中對其進行解密。 該算法的“密鑰長度”,“填充”在Android和iOS上不兼容。

我在NodeJS中使用以下方法解密:

const algorithm = 'aes-128-ecb'; 
const appSecret = '1234567890123456';
decrypt(text) {
    var decipher = crypto.createDecipher(algorithm, appSecret);
    var dec = decipher.update(text, 'hex', 'utf8');
    dec += decipher.final('utf8');
    return dec;
}

Android使用相同的算法以及appSecret和pkcs5填充,並使用MD5對密鑰進行哈希處理。 當android加密數據時,我能夠成功解密。 但是即使加密后使用相同的算法和appSecret,我也無法解密來自iOS的數據。

private secureKey = CryptoJS.enc.Base64.parse('123456789101234567890123456789011');
private secureIV = CryptoJS.enc.Base64.parse('1234567891123456');

var encrypted = CryptoJS.AES.decrypt(myText, this.secureKey, {
      iv: this.secureIV
    });
console.log('DecryptedData: '+encrypted);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM