目前,我正在我的应用程序中进行加密,其中我使用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的实例”。我怎样才能得到字符串格式的?
发布于 2021-01-22 21:52:39
保存公钥时最好使用标准化格式。对于RSA公钥,您可以将它们分层存储,就像Matroesjka娃娃一样。
PUBLIC KEY)组成,其中包含从第2步开始的公钥多行64编码。听起来要做很多工作,但是如果您看起来像这里,您会发现一些名为encodePublicKeyToPem和parsePublicKeyFromPem的方法,它们为您执行这三个步骤(实际上,它在同一个函数中同时执行1和2,这有点遗憾,但并不那么重要)。
这些密钥是相当可移植的,并且也可用于例如OpenSSL或PGP。
https://stackoverflow.com/questions/65851773
复制相似问题