refactor: cleanup

This commit is contained in:
Maciej Krüger 2019-10-23 12:57:23 +02:00 committed by Jacob Heun
parent b8e2414420
commit 487cd076fb
2 changed files with 6 additions and 45 deletions

View File

@ -45,7 +45,7 @@
"keypair": "^1.0.1", "keypair": "^1.0.1",
"libp2p-crypto-secp256k1": "~0.4.0", "libp2p-crypto-secp256k1": "~0.4.0",
"multihashing-async": "~0.7.0", "multihashing-async": "~0.7.0",
"node-forge": "^0.9.1", "node-forge": "~0.9.1",
"pem-jwk": "^2.0.0", "pem-jwk": "^2.0.0",
"protons": "^1.0.1", "protons": "^1.0.1",
"rsa-pem-to-jwk": "^1.1.3", "rsa-pem-to-jwk": "^1.1.3",

View File

@ -121,10 +121,11 @@ function derivePublicFromPrivate (jwKey) {
) )
} }
// bloody dark magic. webcrypto's why.
/* /*
RSA encryption/decryption for the browser with webcrypto workarround
"bloody dark magic. webcrypto's why."
Explanation: Explanation:
- Convert JWK to PEM - Convert JWK to PEM
- Load PEM with nodeForge - Load PEM with nodeForge
@ -144,50 +145,10 @@ function convertKey (key, pub, msg, handle) {
return Buffer.from(forge.util.bytesToHex(fomsg), 'hex') return Buffer.from(forge.util.bytesToHex(fomsg), 'hex')
} }
exports.encrypt = async function (key, msg) { exports.encrypt = function (key, msg) {
return convertKey(key, true, msg, (msg, key) => key.encrypt(msg)) return convertKey(key, true, msg, (msg, key) => key.encrypt(msg))
/* key = Object.assign({}, key)
key.key_ops = ['encrypt']
return webcrypto.subtle.importKey(
'jwk',
key,
{
name: 'RSA-OAEP',
hash: { name: 'SHA-256' }
},
false,
['encrypt']
).then((publicKey) => {
return webcrypto.subtle.encrypt(
{ name: 'RSA-OEAP' },
publicKey,
Uint8Array.from(msg)
)
}).then((enc) => Buffer.from(enc)) */
} }
exports.decrypt = async function (key, msg) { exports.decrypt = function (key, msg) {
return convertKey(key, false, msg, (msg, key) => key.decrypt(msg)) return convertKey(key, false, msg, (msg, key) => key.decrypt(msg))
/* key = Object.assign({}, key)
key.key_ops = ['decrypt']
return webcrypto.subtle.importKey(
'jwk',
key,
{
name: 'RSA-OAEP',
hash: { name: 'SHA-256' }
},
false,
['decrypt']
).then((privateKey) => {
return webcrypto.subtle.decrypt(
{ name: 'RSA-OAEP' },
privateKey,
Uint8Array.from(msg)
)
}).then((dec) => Buffer.from(dec)) */
} }