shotform
This commit is contained in:
parent
5bed911bfc
commit
436edde32c
3 changed files with 8 additions and 16 deletions
|
@ -26,4 +26,5 @@ function base64urlDecode(s) {
|
|||
return window.atob(s); // Regular base64 decoder
|
||||
}
|
||||
|
||||
module = module || {};
|
||||
module.exports = { base64urlDecode, base64urlEncode };
|
||||
|
|
|
@ -38,19 +38,17 @@ function generateKeyPair(alg, size, name) {
|
|||
extractable,
|
||||
["sign", "verify"]
|
||||
)
|
||||
.then(function(key) {
|
||||
.then(key => {
|
||||
var privateKey = window.crypto.subtle
|
||||
.exportKey("jwk", key.privateKey)
|
||||
.then(encodePrivateKey)
|
||||
.then(wrap)
|
||||
.then(rsaPrivateKey);
|
||||
|
||||
var publicKey = window.crypto.subtle.exportKey("jwk", key.publicKey).then(function(jwk) {
|
||||
return encodePublicKey(jwk, name);
|
||||
});
|
||||
|
||||
var publicKey = window.crypto.subtle.exportKey("jwk", key.publicKey).then(jwk => encodePublicKey(jwk, name));
|
||||
return Promise.all([privateKey, publicKey]);
|
||||
});
|
||||
}
|
||||
|
||||
module = module || {};
|
||||
module.exportKey = { arrayBufferToBase64, generateKeyPair };
|
||||
|
|
15
ssh-util.js
15
ssh-util.js
|
@ -5,9 +5,7 @@ function arrayToString(a) {
|
|||
}
|
||||
|
||||
function stringToArray(s) {
|
||||
return s.split("").map(function(c) {
|
||||
return c.charCodeAt();
|
||||
});
|
||||
return s.split("").map(c => c.charCodeAt());
|
||||
}
|
||||
|
||||
function base64urlToArray(s) {
|
||||
|
@ -19,13 +17,7 @@ function pemToArray(pem) {
|
|||
}
|
||||
|
||||
function arrayToPem(a) {
|
||||
return window.btoa(
|
||||
a
|
||||
.map(function(c) {
|
||||
return String.fromCharCode(c);
|
||||
})
|
||||
.join("")
|
||||
);
|
||||
return window.btoa(a.map(c => String.fromCharCode(c)).join(""));
|
||||
}
|
||||
|
||||
function arrayToLen(a) {
|
||||
|
@ -114,7 +106,7 @@ function asnEncodeLen(n) {
|
|||
|
||||
function encodePrivateKey(jwk) {
|
||||
var order = ["n", "e", "d", "p", "q", "dp", "dq", "qi"];
|
||||
var list = order.map(function(prop) {
|
||||
var list = order.map(prop => {
|
||||
var v = checkHighestBit(stringToArray(base64urlDecode(jwk[prop])));
|
||||
var len = asnEncodeLen(v.length);
|
||||
return [0x02].concat(len, v); // int tag is 0x02
|
||||
|
@ -126,4 +118,5 @@ function encodePrivateKey(jwk) {
|
|||
return arrayToPem(a);
|
||||
}
|
||||
|
||||
module = module || {};
|
||||
module.exports = { base64urlToArray, decodePublicKey, encodePublicKey, encodePrivateKey };
|
||||
|
|
Loading…
Reference in a new issue