赞
踩
传入公钥导入,然后加密,具体代码参考如下:
- let base = new util.Base64Helper();
- let pubKey = "HIHHBI*****qQSDFSDFSD";//公钥
- let asyKeyGenerator = cryptoFramework.createAsyKeyGenerator("RSA1024");
- let cipher = cryptoFramework.createCipher("RSA1024|PKCS1"); //创建一个 Cipher (解密)对象
- //引入外部的公钥加密
- let publicKeyDataBlob:cryptoFramework.DataBlob = { data: base.decodeSync(pubKey) };
- let keyGenPromise: cryptoFramework.KeyPair = await asyKeyGenerator.convertKey(publicKeyDataBlob, null);
- await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, keyGenPromise.pubKey, null);
- let put: cryptoFramework.DataBlob = { data: stringToUint8Array("加密内容sadad") };
- const finalRes = await cipher.doFinal(put)let result = base.encodeToStringSync(finalRes.data);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。