【发布时间】:2016-01-21 16:01:06
【问题描述】:
在两个应用程序之间的通信中,我想在 JavaScript 中加密一条信息并使用固定密钥解密来自 Objective-C 客户端的消息(仅出于基本安全考虑)。
加密效果很好:
var command = "mjallo";
var crypto_key = CryptoJS.enc.Base64.parse('280f8bb8c43d532f389ef0e2a5321220');
var crypto_iv = CryptoJS.enc.Base64.parse("CC0A69779E15780A");
// Encrypt and encode
var encrypted = CryptoJS.AES.encrypt(command, crypto_key, {iv: crypto_iv}).toString();
var encrypted_and_encoded = btoa(encrypted);
// encrypted_and_encoded => 'dFBQVDZZS3dGSktoa0J3Y1NQOElpZz09'
// Confirms that decrypt works with CryptoJS:
// Decode and decrypt
var decrypted = CryptoJS.AES.decrypt(atob(encrypted_and_encoded), crypto_key, {iv: crypto_iv});
// decrypted => 'mjallo'
在被 CryptoJS 加密后,你将如何在 Objective-c 中对消息进行解码和解密?
我尝试使用CocoaSecurity 解密,但没有成功。以下是 RubyMotion 语法:
begin
res = CocoaSecurity.aesDecryptWithBase64('dFBQVDZZS3dGSktoa0J3Y1NQOElpZz09', hexKey: '280f8bb8c43d532f389ef0e2a5321220', hexIv: 'CC0A69779E15780A')
rescue NSException => e
p e.reason # => "Length of iv is wrong. Length of iv should be 16(128bits)"
end
【问题讨论】:
标签: javascript objective-c encryption cryptography cryptojs