1
0
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
6.4 KiB

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>QUnit for PKCS5 RSA key reader 'pkcs5pkey.js' for RSA public key</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<!-- script type="text/javascript" src="qunit.js" /script -->
<!-- link rel="stylesheet" href="qunit.css" type="text/css" media="screen" -->
<script src="http://code.jquery.com/qunit/qunit-1.11.0.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.11.0.css" type="text/css" media="screen"/>
<!-- jsrsasign pkcs5pkey external codes -->
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/core.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/x64-core.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/cipher-core.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/aes.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/tripledes.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/md5.js"></script>
<!-- for PKCS5 PBKDF2 -->
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/sha1.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/hmac.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/pbkdf2.js"></script>
<script language="JavaScript" type="text/javascript" src="../ext/jsbn.js"></script>
<script language="JavaScript" type="text/javascript" src="../ext/jsbn2.js"></script>
<script language="JavaScript" type="text/javascript" src="../ext/base64.js"></script>
<script language="JavaScript" type="text/javascript" src="../ext/rsa.js"></script>
<script language="JavaScript" type="text/javascript" src="../ext/rsa2.js"></script>
<script language="JavaScript" type="text/javascript" src="../asn1hex-1.1.js"></script>
<script language="JavaScript" type="text/javascript" src="../pkcs5pkey-1.0.js"></script>
<script language="JavaScript" type="text/javascript" src="../crypto-1.1.js"></script>
<!-- ec -->
<script src="../ext/prng4.js"></script>
<script src="../ext/rng.js"></script>
<script src="../ext/ec.js"></script>
<script src="../ext/ec-patch.js"></script>
<script src="../ecdsa-modified-1.0.js"></script>
<script src="../ecparam-1.0.js"></script>
<script type="text/javascript">
<!--
$(document).ready(function(){
// _test/z2.pub
var z2PubPem = "" +
"-----BEGIN PUBLIC KEY-----\n" +
"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAOtpGHibL8Ue+MXPPufkcrNES40rCT5L\n" +
"RIU9MjTZ8/7owG5bAsiFA9Xxh3uZK1T5QA64jNJVbp2ojHAtNyWPuwsCAwEAAQ==\n" +
"-----END PUBLIC KEY-----\n";
var z2PubHex = "305c300d06092a864886f70d0101010500034b003048024100eb6918789b2fc51ef8c5cf3ee7e472b3444b8d2b093e4b44853d3234d9f3fee8c06e5b02c88503d5f1877b992b54f9400eb88cd2556e9da88c702d37258fbb0b0203010001";
var z2RawPubHex = "3048024100eb6918789b2fc51ef8c5cf3ee7e472b3444b8d2b093e4b44853d3234d9f3fee8c06e5b02c88503d5f1877b992b54f9400eb88cd2556e9da88c702d37258fbb0b0203010001";
// _gitpg/jsrsasign/test/eckey/k1.pub.der
var k1PubPem = "" +
"-----BEGIN PUBLIC KEY-----\n" +
"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEoBUyo8CQAFPeYPvv78ylh5MwFZjT\n" +
"CLQeb042TjiMJxG+9DLFmRSMlBQ9T/RsLLc+PmpB1+7yPAR+oR5gZn3kJQ==\n" +
"-----END PUBLIC KEY-----\n";
var k1PubHex = "3059301306072a8648ce3d020106082a8648ce3d03010703420004a01532a3c0900053de60fbefefcca58793301598d308b41e6f4e364e388c2711bef432c599148c94143d4ff46c2cb73e3e6a41d7eef23c047ea11e60667de425";
// ======= TEST ===================================================================================
test("getRSAKeyFromPublicPKCS8Hex z2", function() {
var k = PKCS5PKEY.getRSAKeyFromPublicPKCS8Hex(z2PubHex);
expect(2);
equal(k.n.toString(16), "eb6918789b2fc51ef8c5cf3ee7e472b3444b8d2b093e4b44853d3234d9f3fee8c06e5b02c88503d5f1877b992b54f9400eb88cd2556e9da88c702d37258fbb0b", "rsaKey.n");
equal(k.e.toString(16), "10001", "rsaKey.e");
});
test("getRSAKeyFromPublicPKCS8PEM z2", function() {
var k = PKCS5PKEY.getRSAKeyFromPublicPKCS8PEM(z2PubPem);
expect(2);
equal(k.n.toString(16), "eb6918789b2fc51ef8c5cf3ee7e472b3444b8d2b093e4b44853d3234d9f3fee8c06e5b02c88503d5f1877b992b54f9400eb88cd2556e9da88c702d37258fbb0b", "rsaKey.n");
equal(k.e.toString(16), "10001", "rsaKey.e");
});
test("parsePublicPKCS8PEM z2(RSA)", function() {
var r = PKCS5PKEY.parsePublicPKCS8Hex(z2PubHex);
expect(3);
equal(r.algoid, "2a864886f70d010101", "algoid");
equal(r.algparam, null, "algparam");
equal(r.key, "3048024100eb6918789b2fc51ef8c5cf3ee7e472b3444b8d2b093e4b44853d3234d9f3fee8c06e5b02c88503d5f1877b992b54f9400eb88cd2556e9da88c702d37258fbb0b0203010001");
});
test("parsePublicPKCS8PEM k1(EC)", function() {
var r = PKCS5PKEY.parsePublicPKCS8Hex(k1PubHex);
expect(3);
equal(r.algoid, "2a8648ce3d0201", "algoid");
equal(r.algparam, "2a8648ce3d030107", "algparam");
equal(r.key, "04a01532a3c0900053de60fbefefcca58793301598d308b41e6f4e364e388c2711bef432c599148c94143d4ff46c2cb73e3e6a41d7eef23c047ea11e60667de425", "key");
});
test("parsePublicRawRSAKeyHex key of z2(RSA)", function() {
var r = PKCS5PKEY.parsePublicRawRSAKeyHex(z2RawPubHex);
expect(2);
equal(r.n, "00eb6918789b2fc51ef8c5cf3ee7e472b3444b8d2b093e4b44853d3234d9f3fee8c06e5b02c88503d5f1877b992b54f9400eb88cd2556e9da88c702d37258fbb0b", "n");
equal(r.e, "010001", "e");
});
test("getKeyFromPublicPKCS8PEM z2(RSA)", function() {
var key = PKCS5PKEY.getKeyFromPublicPKCS8PEM(z2PubPem);
expect(3);
equal(key.type, "RSA", "type");
equal(key.n.compareTo(new BigInteger("00eb6918789b2fc51ef8c5cf3ee7e472b3444b8d2b093e4b44853d3234d9f3fee8c06e5b02c88503d5f1877b992b54f9400eb88cd2556e9da88c702d37258fbb0b", 16)), 0, "n");
equal(key.e, 65537, "e(65537)");
});
test("getKeyFromPublicPKCS8PEM k1(EC)", function() {
var key = PKCS5PKEY.getKeyFromPublicPKCS8PEM(k1PubPem);
expect(3);
equal(key.type, "EC", "type");
equal(key.curveName, "secp256r1", "curveName");
equal(key.pubKeyHex, "04a01532a3c0900053de60fbefefcca58793301598d308b41e6f4e364e388c2711bef432c599148c94143d4ff46c2cb73e3e6a41d7eef23c047ea11e60667de425", "pubKeyHex");
});
});
-->
</script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">test markup</div>
</body>
</html>