-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from restuhaqza/Feature/core
add main core feature and unit testing #DevCJog25
- Loading branch information
Showing
9 changed files
with
870 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
var crypto = require("crypto") | ||
|
||
var private_key | ||
var public_key | ||
|
||
function setPrivateKey(value) { | ||
private_key = value | ||
} | ||
|
||
function getPrivateKey(value) { | ||
return private_key | ||
} | ||
|
||
function setPublicKey(value) { | ||
public_key = value | ||
} | ||
|
||
function getPublicKey(value) { | ||
return public_key | ||
} | ||
|
||
function createSign(message) { | ||
const signer = crypto.createSign("sha256") | ||
signer.update(message) | ||
signer.end() | ||
|
||
const signature = signer.sign(getPrivateKey(), "base64") | ||
return signature | ||
} | ||
|
||
function verifySign(message, signature) { | ||
const verifier = crypto.createVerify("sha256") | ||
verifier.update(message) | ||
verifier.end() | ||
|
||
const verified = verifier.verify(getPublicKey(), signature, "base64") | ||
return verified | ||
} | ||
|
||
module.exports = { | ||
setPrivateKey, | ||
getPrivateKey, | ||
setPublicKey, | ||
getPublicKey, | ||
createSign, | ||
verifySign | ||
} |
Oops, something went wrong.