2016-12-06 52 views

回答

1

我找到問題的解決方案:How do you verify an RSA SHA1 signature in Python?

下面是做驗證演示工作:

import base64 

from M2Crypto import BIO, RSA, EVP 

ori = "content of origin string" 
sig = "content of signature string" 

with open("./public.pem") as f: 
    pem = f.read() 
    bio = BIO.MemoryBuffer(pem) 
    rsa = RSA.load_pub_key_bio(bio) 

    pubkey = EVP.PKey() 
    pubkey.assign_rsa(rsa) 
    pubkey.reset_context(md="sha256") 
    pubkey.verify_init() 
    pubkey.verify_update(ori) 
    print pubkey.verify_final(base64.b64decode(sig)) # 1 means verify OK 
1

你試過pyopenssl

OpenSSL.crypto.verify(certificate, signature, data, digest) 
+0

第一個參數證書是對應於產生的私鑰的X509實例簽名,如果我只有公鑰,如何生成X509實例? –

相關問題