2012-03-26 107 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下加密++維基更詳細地討論。