问题描述
想要将以下 Node Crypto
示例转换为等效的 Swift commonCrypto
:
function encrypt(key,text){
let iv = crypto.randomBytes(IV_LENGTH);
let cipher = crypto.createCipheriv('aes-256-cbc',Buffer.from(key),iv);
let encrypted = cipher.update(text);
encrypted = Buffer.concat([encrypted,cipher.final()]);
let final_encrypted = iv.toString('hex') + ':' + encrypted.toString('hex');
console.log(final_encrypted); // <-- final encrypted string
}
function decrypt(key,enc_text){
let textParts = enc_text.split(':');
let iv = Buffer.from(textParts.shift(),'hex');
let encryptedText = Buffer.from(textParts.join(':'),'hex');
let decipher = crypto.createDecipheriv('aes-256-cbc',iv);
let decrypted = decipher.update(encryptedText);
let final = decipher.final();
decrypted = Buffer.concat([decrypted,final]);
console.log(decrypted.toString()); // <-- final decrypted string
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)