Using pycrypto, how to import a RSA public key and use it to encrypt a string?

后端 未结 7 1063
孤街浪徒
孤街浪徒 2020-12-28 10:06

The RSA public key:

pubkey = \'MIGfMA0GCSqGSIb3DQEBA3UAA4GNADCBiQKBgQC35eMaYoJXEoJt5HxarHkzDBEMU3qIWE0HSQ77CwP/8UbX07W2XKwngUyY4k6Hl2M/n9TOZMZsiBzer/fqV+QNPN1m9M94eU

7条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-28 10:36

    By using:

    RSA.importKey(externKey)
    

    with parameter externKey look like the following:

    -----BEGIN PUBLIC KEY-----
    MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAybVqRvfYvWbLsB98BqkD
    lWd0/5y6SyhHt6/r6M0l7JXBweqMvxVt7XmI2yqPL56YxzcgQ8ycDkoqHJ+XozgP
    iRnLNpYRlCzsiaOElbmQcnrI8iOb9Ahm6j0cbBB1S8VNvD+u9RQJt53zPxPj8/Dq
    f1oNGFXOM8udNYWZaRCukLs/TumsAn0a+BF4639WtFiUvTWdVhlyvCQTs49ytRkH
    rXH30RkB528RIvTGeW8xBTV4NaiTIzAEKCVSPagLr4Hzbb9b5+bODic/zkLGQazy
    /NKOFgiB7kD2+WEMcuhTr5noeXau0PDAhgmrBhzzWOjUwwaO+ACvJLkPXZfjhy7P
    +wIDAQAB
    -----END PUBLIC KEY-----
    

    You shouldn't b64decode the externKey and the string should start with "-----BEGIN PUBLIC KEY-----" and "-----END PUBLIC KEY-----".

提交回复
热议问题