Created
March 12, 2013 17:34
-
-
Save ipconfiger/5145056 to your computer and use it in GitHub Desktop.
山寨版SSL,HTML端Javascript用公钥加密密码,在Python端用私钥解密活得明文密码。这样在POST传输 的过程中就是加密了的密码了,公钥可以直接输出到HTML。
javascript使用了https://github.com/ziyan/javascript-rsa 这个库 第一步通过 命令
生成私钥:
openssl genrsa -out privatekey.key 1024
通过私钥生成公钥:
openssl rsa -in privatekey.key -pubout -out pubkey.key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
<script src="/jquery.js"></script> | |
<script src="/jsbn.js"></script> | |
<script src="/rsa.js"></script> | |
<script src="/sha1.js"></script> | |
<script type="text/javascript"> | |
function encrypt() { | |
var pem = $("#public_key").val(); | |
var password = $("#password").val(); | |
var $key = RSA.getPublicKey(pem); | |
$("#data").val(RSA.encrypt(password, $key)); | |
} | |
</script> | |
</head> | |
<body> | |
<form> | |
<dl> | |
<dt>public key</dt> | |
<dd> | |
<textarea id="public_key" cols="100" rows="5">-----BEGIN PUBLIC KEY-----MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMYQWDqtLgDKlQvWzacGeBMQpbicd/uoXAvgLNpFZLM7zuYFDhrYncRsl8LIHK0K3f7e1aFmUVgM4LrKU2WFIw0CAwEAAQ==-----END PUBLIC KEY-----</textarea> | |
</dd> | |
</dl> | |
<dl> | |
<dt>password</dt> | |
<dd><input name="password" id="password" type="text" size="60"/></dd> | |
</dl> | |
<dl> | |
<dt><input type="button" onclick="encrypt()" value="make it"/></dt> | |
<dd> | |
<textarea id="data" cols="100" rows="5"></textarea> | |
</dd> | |
</dl> | |
</form> | |
<script type="text/javascript"> | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from M2Crypto import RSA, BIO | |
import base64 | |
private = """-----BEGIN RSA PRIVATE KEY----- | |
MIIBOwIBAAJBALQxMmjGJRZlZLZbB1H2EwBAKK7qgfWUyDh3G2VLRfCY5rRVkNG2 | |
7/cQBGXuMZY7+HXV+CfqOAfEdZVB2JIyrvMCAwEAAQJAf9FGCLxFIpXZ0uDPWHxN | |
Dih0s171wNZBEIysijXS7s7VdIOYsK/EBixQtC+Sk6dudt27PWSReQvaP1viFpaQ | |
gQIhAOhAq5WDoXXxXcvOZmGSRzGTsq5MIlg1kTZjAk8YNtVLAiEAxp3ReEOCIgNQ | |
vCKyYDtSSux3r2L8FcG9EysT3wQ5C/kCIF+ypgDJaDIs7jUYKt9xYpxu+2UOQeiO | |
yfLbAQyOManZAiEAtTlO5eMDHDHWOrOV+oRmJAL7ecZhqSBres/1g6oAu1ECIQDG | |
Wd52QpUrkQrDgZW2u0zGJusGESP+1vu6zFTER0vWtQ== | |
-----END RSA PRIVATE KEY----- | |
""" | |
bio = BIO.MemoryBuffer(private) | |
rsa = RSA.load_key_bio(bio) | |
rsa.private_decrypt(base64.decodestring("bDYzKL6pVybEgWbu5JzKM9BJDwS6VlgRQzKwR6Z9Xt1b6W31LaxB2OB0Gyt+TJFkoPdHqxE34LMag+hgoA4C8A=="),RSA.pkcs1_padding) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment