Skip to content

Commit

Permalink
Merge pull request #2 from restuhaqza/Feature/core
Browse files Browse the repository at this point in the history
add main core feature and unit testing #DevCJog25
  • Loading branch information
restuhaqza authored Oct 27, 2019
2 parents 72902ca + 7289836 commit 6ed5346
Show file tree
Hide file tree
Showing 9 changed files with 870 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
47 changes: 47 additions & 0 deletions index.js
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
}
Loading

0 comments on commit 6ed5346

Please sign in to comment.