2011-07-31 145 views
1

我想讓OpenSSL.net 1)創建一個密鑰對用於CA簽名和2)使用此CA創建和簽署證書。我設法創建了RSA/SHA1 X509CertificateAuthority,並創建了X509Request和密鑰,但是我遇到了實際簽名請求的問題。使用OpenSSL.net簽署證書的問題

'create the request and request key 
    Dim rsa As OpenSSL.Crypto.RSA = New OpenSSL.Crypto.RSA() 
    rsa.GenerateKeys(1024, 65569, Nothing, Nothing) 
    Dim req_key As OpenSSL.Crypto.CryptoKey = New OpenSSL.Crypto.CryptoKey(rsa) 
    Dim req_key_b As OpenSSL.Core.BIO = OpenSSL.Core.BIO.MemoryBuffer 
    req_key_b.Write(req_key.GetRSA.PrivateKeyAsPEM) 
    WriteBio(req_key_b, IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "req.key")) 

    'make the request 
    Dim req As OpenSSL.X509.X509Request = New OpenSSL.X509.X509Request(3, "CN=newcert", req_key) 

    Dim req_cert As OpenSSL.X509.X509Certificate = ca.ProcessRequest(req, Now, Now.AddDays(365)) 
    '** ^^^ Exception on this line ^^^ *** 
    Dim req_cert_b As OpenSSL.Core.BIO = OpenSSL.Core.BIO.MemoryBuffer 
    req_cert.Write(req_cert_b) 
    WriteBio(req_cert_b, IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "req.crt")) 

我正在上線的OpenSslException上面提到的,與消息

error:0606B06E:digital envelope routines:EVP_SignFinal:wrong public key type error:0D0C3006:asn1 encoding routines:ASN1_item_sign:EVP lib

任何想法?

+0

我最終放棄了openSSL並改用了BouncyCastle。更好的文檔 – insertjokehere

回答

1

我有同樣的錯誤。經過一番研究,它似乎在工作的時候手動指定的消息摘要,如下所示:

var certificate = ca.ProcessRequest(req, Now, Now.AddDays(365), MessageDigest.SHA1) 

您還可以指定默認的消息摘要在openssl.conf:default_md。但你可能不初始化一個配置的CA,就像我:)

var ca = new X509CertificateAuthority(pkcs12.Certificate, pkcs12.PrivateKey, new SimpleSerialNumber(42), null); 

我知道你放棄了,並使用BouncyCastle的替代,但希望這是別人:)

0

其實這個問題是非常有用的缺省摘要方法DSS1在用於簽名時會發生錯誤。因此指定其他簽名方法將解決該問題。