flutter - 在 Dart 中将 privateKey 转换为 PKCS#8 格式

标签 flutter dart rsa private-key

在使用 RSA 算法的 FLUTTER - DART 中,我得到了一个私钥。我有这种方法可以将 privateKey 编码为 PKCS#1 格式的 PEM,但我需要一种将 privateKey 编码为 PKCS#8 格式的方法。我在互联网上找不到任何相关信息。

Uint8List _encodePrivateKeyToPemPKCS1(RSAPrivateKey privateKey) {
    var topLevel = new ASN1Sequence();

    var version = ASN1Integer(BigInt.from(0));
    var modulus = ASN1Integer(privateKey.n!);
    var publicExponent = ASN1Integer(privateKey.exponent!);
    var privateExponent = ASN1Integer(privateKey.privateExponent!);
    var p = ASN1Integer(privateKey.p!);
    var q = ASN1Integer(privateKey.q!);
    var dP = privateKey.privateExponent! % (privateKey.p! - BigInt.from(1));
    var exp1 = ASN1Integer(dP);
    var dQ = privateKey.privateExponent! % (privateKey.q! - BigInt.from(1));
    var exp2 = ASN1Integer(dQ);
    var iQ = privateKey.q!.modInverse(privateKey.p!);
    var co = ASN1Integer(iQ);

    topLevel.add(version);
    topLevel.add(modulus);
    topLevel.add(publicExponent);
    topLevel.add(privateExponent);
    topLevel.add(p);
    topLevel.add(q);
    topLevel.add(exp1);
    topLevel.add(exp2);
    topLevel.add(co);

    return topLevel.encodedBytes;
}

最佳答案

关于flutter - 在 Dart 中将 privateKey 转换为 PKCS#8 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71492016/

相关文章:

java - Android Java - 使用 RSA 公钥 .PEM 加密字符串

android - 无法找到ADB-装有Flutter的Android Studio

dart - Flutter 在 RaisedButton 上设置状态 onPressed

android - 在之前由 android 构建的其他构建 apk 上通过 flutter 在 Play Store 上更新 apk 构建

Dart-在每次测试之后或之前如何运行功能?

animation - 对容器窗口小部件进行动画处理,使屏幕向左移动

json - 如何在 Dart 控制台应用程序中读取 JSON 文件?

json - 将 JSON 映射到类对象

java - 将消息和签名转换为 BouncyCaSTLe CMSSignedData 对象

java - 如何使用 RSA 公钥加密 java.util.Properties 对象(可以是任意大小)?