2012-03-26 106 views
2

我必须编写一个程序来建立与USB设备的安全通信。我必须使用以PKCS#1格式存储的私钥。由于我已经使用Crypto ++作为我的程序的一部分,因此我想将其用于此目的。从内存加载RSA PKCS#1私钥?

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

回答

2

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 

保存和加载密钥是在Keys and Formats下加密++维基更详细地讨论。