{"rsdb":{"rid":"242472","subhead":"","postdate":"0","aid":"166948","fid":"54","uid":"1","topic":"1","content":"

\u3000\u3000\u4f7f\u7528RSA\u516c\u94a5\u89e3\u5bc6\uff0c\u7528openssl\u547d\u4ee4\u5c31\u662fopenssl rsautl -verify -in cipher_text -inkey public.pem -pubin -out clear_text\uff0c\u4f46\u5176python<\/a>\u7f51\u4e0a\u8fd8\u771f\u6ca1\u6709\u627e\u5230\u6709\u535a\u6587\u53bb\u5199\uff0c\u53ea\u6709hash\u7684rsa\u89e3\u7b7e\u540d\u3002<\/p>

\u3000\u3000\u8fd9\u91cc\u4f7f\u7528rsa\u5e93\uff0c\u5982\u679c\u6ca1\u6709\u53ef\u4ee5\u5230\u5b98\u65b9\u7f51\u5740\u4e0b\u8f7d<\/a>\u3002<\/p>

\u3000\u3000\u60f3\u4e86\u60f3\u539f\u7406\uff0c\u7136\u540e\u5230rsa\u5e93\u7684python<\/a>\u4ee3\u7801\u91cc\u627e\u4e86\u627e\uff0c\u4eceverify\u7684\u4ee3\u7801\u91cc\u63d0\u53d6\u4e86\u51fa\u6765\uff0c\u53c8\u8bd5\u9a8c\u4e86\u8bd5\u9a8c\uff0c\u4e00\u5207OK\u4e86\u3002<\/p>

\u3000\u3000\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>

#! \/usr\/bin\/env python
# -*- coding: utf-8 -*-
import sys
#rsa
from rsa import PublicKey, common, transform, core
def f(cipher, PUBLIC_KEY):
        public_key = PublicKey.load_pkcs1(PUBLIC_KEY)
        encrypted = transform.bytes2int(cipher)
        decrypted = core.decrypt_int(encrypted, public_key.e, public_key.n)
        text = transform.int2bytes(decrypted)
 
        if len(text) > 0 and text[0] == '\\x01':
            pos = text.find('\\x00')
            if pos > 0:
                return text[pos+1:]
            else:
                return None
 
fn = sys.stdin.readline()[:-1]
public_key = sys.stdin.readline()[:-1]
x = f(open(fn).read(), open(public_key).read())
print x<\/p>

\u7528shell\u9a8c\u8bc1\u5982\u4e0b\uff1a<\/strong><\/p>

$ openssl genrsa -out pri2048.pem 2048
Generating RSA private key, 2048 bit long modulus
..+++
..............................................+++
e is 65537 (0x10001)
 $ openssl rsa -in pri2048.pem -out pub2048.pem -RSAPublicKey_out
writing RSA key
 $ echo -n 'Just a test' >1.txt
 $ openssl rsautl -sign -in 1.txt -inkey pri2048.pem -out 1.bin
 $ { echo 1.bin; echo pub2048.pem; } | .\/test_rsa.py
Just a test<\/p>

\u3000\u3000\u4e00\u5207OK\uff0c\u6ce8\u610f\uff0c\u516c\u94a5pem\u4ece\u79c1\u94a5\u91cc\u6790\u51fa\u5fc5\u987b\u7528-RSAPublicKey_out\uff0c\u8fd9\u6837pem\u6587\u4ef6\u7684\u7b2c\u4e00\u884c\u548c\u6700\u540e\u4e00\u884c\u4e3a\u4ee5\u4e0b\uff0c\u8fd9\u6837rsa.PublicKey.load_pkcs1\u624d\u4f1a\u8ba4\u8bc6\u3002<\/p>

\u3000\u3000-----BEGIN RSA PUBLIC KEY-----<\/p>

\u3000\u3000-----END RSA PUBLIC KEY-----<\/p>","orderid":"0","title":"Python\u4f7f\u7528RSA\u5e93\u505a\u516c\u94a5\u89e3\u5bc6","smalltitle":"","mid":"0","fname":"linux\u7f16\u7a0b\u57fa\u7840","special_id":"0","bak_id":"0","info":"0","hits":"238","pages":"1","comments":"0","posttime":"2017-12-14 14:32:02","list":"1513233122","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"Python<\/A> \u4f7f\u7528<\/A> RSA<\/A> \u516c\u94a5<\/A> \u89e3\u5bc6<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"113.110.149.170","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"Python\u4f7f\u7528RSA\u5e93\u505a\u516c\u94a5\u89e3\u5bc6","lastview":"1708213381","digg_num":"2","digg_time":"1711120828","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}