HarmonyOS 鸿蒙Next RSA加密后得到DataBlob类如何转成base64字符串
HarmonyOS 鸿蒙Next RSA加密后得到DataBlob类如何转成base64字符串
<markdown _ngcontent-egy-c147="" class="markdownPreContainer">
RSA加密后得到DataBlob类如何转成base64字符串啊?
深色代码主题
复制
try {
let publicPkcs1Str1024 = `-----BEGIN PUBLIC KEY-----
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
-----END PUBLIC KEY-----`;
let cipher = cryptoFramework.createCipher('RSA1024|PKCS1');
let asyKeyGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024');
let keyPairData = asyKeyGenerator.convertPemKeySync(publicPkcs1Str1024, null);
let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(text, 'utf-8').buffer) };
cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, keyPairData.pubKey, null);
let encryptData = cipher.doFinalSync(plainText);
console.log(`RSA加密成功:-----${encryptData.data}`);
return encryptData;
} catch (err) {
console.log(`RSA加密出错:-----${err}`);
return text;
}
更多关于HarmonyOS 鸿蒙Next RSA加密后得到DataBlob类如何转成base64字符串的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
2 回复
Uint8Array转base64字符串:可以通过Base64Helper工具类的encodeToStringSync方法进行转换
new util.Base64Helper().encodeToStringSync(encryptData.data);
api文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-util-V5#encodetostringsync9
new util.Base64Helper().encodeToStringSync(encryptData.data);
api文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-util-V5#encodetostringsync9
更多关于HarmonyOS 鸿蒙Next RSA加密后得到DataBlob类如何转成base64字符串的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html