mirror of
https://github.com/fluencelabs/js-libp2p-crypto
synced 2025-03-15 17:31:06 +00:00
refactor: cleanup
This commit is contained in:
parent
b8e2414420
commit
487cd076fb
@ -45,7 +45,7 @@
|
||||
"keypair": "^1.0.1",
|
||||
"libp2p-crypto-secp256k1": "~0.4.0",
|
||||
"multihashing-async": "~0.7.0",
|
||||
"node-forge": "^0.9.1",
|
||||
"node-forge": "~0.9.1",
|
||||
"pem-jwk": "^2.0.0",
|
||||
"protons": "^1.0.1",
|
||||
"rsa-pem-to-jwk": "^1.1.3",
|
||||
|
@ -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:
|
||||
- Convert JWK to PEM
|
||||
- Load PEM with nodeForge
|
||||
@ -144,50 +145,10 @@ function convertKey (key, pub, msg, handle) {
|
||||
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))
|
||||
|
||||
/* 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))
|
||||
|
||||
/* 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)) */
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user