#!/usr/local/bin/ruby
require "openssl"
require "base64"
require "cgi"
require "erb"
KEY_FILE = "private_key.pem"
rsa = OpenSSL::PKey::RSA.new(File.read(KEY_FILE))
cgi = CGI.new()
cgi.out(){
if cgi.has_key?("password") then
rsa.private_decrypt(Base64.decode64(cgi["password"]))
else
ERB.new(DATA.read).result
end
}
__END__
<html>
<head>
<script src="prototype.js" type="text/javascript"></script>
<script src="base64.js" type="text/javascript"></script>
<script src="jsbn.js" type="text/javascript"></script>
<script src="prng4.js" type="text/javascript"></script>
<script src="rng.js" type="text/javascript"></script>
<script src="rsa.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
rsa = new JSBN.RSA.RSAKey();
rsa.setPublic("<%= "%x" % rsa.n %>", JSBN.RSA.byte2Hex(<%= rsa.e %>));
function encrypt(){
var password = hex2b64(rsa.encrypt($("password").value));
new Ajax.Request("<%= ENV['SCRIPT_NAME'] %>",{
method: "post",
postBody: 'password='+encodeURIComponent(password),
onSuccess: function(http){
alert(http.responseText);
}
});
}
</script>
Password : <input type="password" id="password"></input>
<input type="button" value="send" onClick="encrypt()"></input>
</body>
</html>
Author:kovayashi
・嫌いなもの
→好きなもの
・インストール
→バンドル
・バックアップ
→アップロード
コメントの投稿