我目前正在我的flutter应用程序中从事加密工作,其中我正在使用RSA密钥对生成器通过以下代码获取公共和私有密钥:
import 'package:rsa_encrypt/rsa_encrypt.dart';
import 'package:pointycastle/api.dart' as crypto;
//Future to hold our KeyPair
Future<crypto.AsymmetricKeyPair> futureKeyPair;
//to store the KeyPair once we get data from our future
crypto.AsymmetricKeyPair keyPair;
Future<crypto.AsymmetricKeyPair<crypto.PublicKey, crypto.PrivateKey>> getKeyPair()
{
var helper = RsaKeyHelper();
return helper.computeRSAKeyPair(helper.getSecureRandom());
}
现在,我想获取字符串格式的keyPair.publicKey,但是如果我打印keyPair.publicKey,它将显示“ RSA publicKey的实例”。如何获取字符串格式的内容?
保存公钥时始终最好使用标准化格式。对于RSA公钥,您可以将它们存储在层中,就像Matroesjka娃娃一样。
PUBLIC KEY
)组成,中间是第2步的多行以64为底的公钥编码。听起来需要做很多工作,但是如果您在这里查看,就会发现方便的方法被调用,encodePublicKeyToPem
并且parsePublicKeyFromPem
可以为您完成这三个步骤(实际上,它在同一函数中同时执行了1和2,这有点可惜,但事实并非如此)重要)。
这些密钥是相当可移植的,并且还可以通过例如OpenSSL或PGP使用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句