RSA SIgnature
by dshilkret
HTML
<html>
<head>
<title>Sample Application for RSA signing in JavaScript</title>
<script language="JavaScript" type="text/javascript" src="../jsrsasign-all-min.js"></script>
<script language="JavaScript" type="text/javascript">
function doSign() {
var rsa = new RSAKey();
rsa.readPrivateKeyFromPEMString(document.form1.prvkey1.value);
var hashAlg = document.form1.hashalg.value;
var hSig = rsa.sign(document.form1.msgsigned.value, hashAlg);
document.form1.siggenerated.value = linebrk(hSig, 64);
}
function doVerify() {
var sMsg = document.form1.msgverified.value;
var hSig = document.form1.sigverified.value;
var pubKey = KEYUTIL.getKey(document.form1.cert.value);
var isValid = pubKey.verify(sMsg, hSig);
// display verification result
if (isValid) {
_displayStatus("valid");
} else {
_displayStatus("invalid");
}
}
function copyMsgAndSig() {
_displayStatus("reset");
document.form1.msgverified.value = document.form1.msgsigned.value;
document.form1.sigverified.value = document.form1.siggenerated.value;
}
function _displayStatus(sStatus) {
var div1 = document.getElementById("verifyresult");
if (sStatus == "valid") {
div1.style.backgroundColor = "skyblue";
div1.innerHTML = "This signature is *VALID*.";
} else if (sStatus == "invalid") {
div1.style.backgroundColor = "deeppink";
div1.innerHTML = "This signature is *NOT VALID*.";
} else {
div1.style.backgroundColor = "yellow";
div1.innerHTML = "Please fill values below and push [Verify this sigunature] button.";
}
}
</script>
<style type="text/css">
TD {vertical-align: top}
</style>
</head>
<body>
<h1>Sample Application for RSA signing in JavaScript</h1>
<form name="form1">
<table border="0">
<tr><th>Signer</th><th></th><th>Verifier</th></tr>
<tr>
<td>
PEM RSA Private Key<br/>
<!-- _test/z5.* for X.509v1 certificate and private key -->
<textarea name="prvkey1" rows="10" cols="65">
-----BEGIN RSA PRIVATE...
JavaScript
1 /* crypto-1.2.4.js (c) 2013-2020 Kenji Urushima | kjur.github.io/jsrsasign/license
2 */
3 /*
4 * crypto.js - Cryptographic Algorithm Provider class
5 *
6 * Copyright (c) 2013-2020 Kenji Urushima ([email protected])
7 *
8 * This software is licensed under the terms of the MIT License.
9 * https://kjur.github.io/jsrsasign/license
10 *
11 * The above copyright and license notice shall be
12 * included in all copies or substantial portions of the Software.
13 */
14
15 /**
16 * @fileOverview
17 * @name crypto-1.1.js
18 * @author Kenji Urushima [email protected]
19 * @version 1.2.4 (2020-Jul-28)
20 * @since jsrsasign 2.2
21 * @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a>
22 */
23
24 /**
25 * kjur's class library name space
26 * @name KJUR
27 * @namespace kjur's class library name space
28 */
29 if (typeof KJUR == "undefined" || !KJUR) KJUR = {};
30 /**
31 * kjur's cryptographic algorithm provider library name space
32 * <p>
33 * This namespace privides following crytpgrahic classes.
34 * <ul>
35 * <li>{@link KJUR.crypto.MessageDigest} - Java JCE(cryptograhic extension) style MessageDigest class</li>
36 * <li>{@link KJUR.crypto.Signature} - Java JCE(cryptograhic extension) style Signature class</li>
37 * <li>{@link KJUR.crypto.Cipher} - class for encrypting and decrypting data</li>
38 * <li>{@link KJUR.crypto.Util} - cryptographic utility functions and properties</li>
39 * </ul>
40 * NOTE: Please ignore method summary and document of this namespace. This caused by a bug of jsdoc2.
41 * </p>
42 * @name KJUR.crypto
43 * @namespace
44 */
45 if (typeof KJUR.crypto == "undefined" || !KJUR.crypto) KJUR.crypto = {};
46
47 /**
48 * static object for cryptographic function utilities
49 * @name KJUR.crypto.Util
50 * @class static object for cryptographic function utilities
51 * @property {Array} DIGESTINFOHEAD PKCS#1 DigestInfo...