javascript-blowfish-unique
Version:
Blowfish encryption library Javascript, jquery,coffeescript (blowfish.js)
70 lines (56 loc) • 1.98 kB
HTML
<html>
<head>
<title>blowfish</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="Blowfish.js"></script>
<script type="text/javascript" src="http://yandex.st/jquery/1.4.2/jquery.min.js"></script>
<!-- <script type="text/javascript" src="jquery.blowfish.js"></script>-->
</head>
<body>
<form>
<textarea name="text" rows="12" cols="70"></textarea><br/>
<input type="text" name="password" size="56" /><br/>
<input type="submit" name="encrypt" value="Зашифровать">
<input type="submit" name="decrypt" value="Расшифровать"><br/>
<textarea name="result" rows="12" cols="70"></textarea>
</form>
<script type="text/javascript">
$(function() {
$('input[name=encrypt]').submit(function(event) {
event.preventDefault();
});
$('input[name=encrypt]').click(function(event) {
try {
var key = $('input[name=password]').val();
var text = $('textarea[name=text]').val();
var bf = new Blowfish(key);
var res = bf.encrypt(text);
res = bf.base64Encode(res);
$('textarea[name=result]').val(res);
} catch(ex) {
if (window.console && console.log) {
console.log(ex)
}
}
return false;
});
$('input[name=decrypt]').click(function() {
try {
var key = $('input[name=password]').val();
var text = $('textarea[name=text]').val();
var bf = new Blowfish(key);
text = bf.base64Decode(text);
var res = bf.decrypt(text);
res = bf.trimZeros(res);
$('textarea[name=result]').val(res);
} catch(ex) {
if (window.console && console.log) {
console.log(ex)
}
}
return false;
});
});
</script>
</body>
</html>