【问题标题】:Load RSA PKCS#1 private key from memory?从内存中加载 RSA PKCS#1 私钥?
【发布时间】:2012-03-26 09:01:45
【问题描述】:

我必须编写一个程序来建立与 USB 设备的安全通信。我必须使用它生成的私钥,它以 PKCS#1 格式存储。由于我在程序的一部分中使用了 Crypto++,因此我也想将其用于此目的。

但是,我找不到从内存中导入 RSA 私钥的方法。它只接受 PKCS#8 格式的私钥。一些专业人士可以向我展示如何做到这一点的示例代码吗?非常感谢!

【问题讨论】:

    标签: crypto++


    【解决方案1】:

    PKCS#1 格式是 ASN.1 编码的。对于RSAPublicKeyRSAPrivateKey,很简单:

    RSA::PublicKey publicKey(...);
    
    ByteQueue queue;
    publicKey.Save(queue);
    
    // The public key is now in the ByteQueue in PKCS #1 format
    
    // ------------
    
    // Load a PKCS #1 private key
    byte key[] = {...}
    ArraySource arr(key, sizeof(key));
    
    RSA::PrivateKey privateKey;
    privateKey.Load(arr);
    
    // The private key is now ready to use
    

    Crypto++ wiki 的 Keys and Formats 下更详细地讨论了保存和加载密钥。

    【讨论】:

      猜你喜欢
      • 2018-08-04
      • 1970-01-01
      • 1970-01-01
      • 2021-06-22
      • 1970-01-01
      • 1970-01-01
      • 2012-09-07
      • 1970-01-01
      • 2012-06-13
      相关资源
      最近更新 更多