Ind.ie is now Small Technology Foundation.
Commit 7d471fa1 authored by wim-vantomme's avatar wim-vantomme

Added libsodium password encryption.

parent ea80463e
......@@ -110,3 +110,5 @@ $RECYCLE.BIN/
# Others
lib/
data/
public/js/script.js
server/files
const sodium = require('libsodium-wrappers')
class Keys {
constructor () {
this.privateKey
this.publicKey
this.salt
this.password
this.keySettings = {
keyLength: sodium.crypto_pwhash_BYTES_MIN,
opslimit: sodium.crypto_pwhash_OPSLIMIT_MODERATE,
memlimit: 10777215,
algorithm: sodium.crypto_pwhash_ALG_DEFAULT,
saltBytes: sodium.crypto_pwhash_SALTBYTES
}
}
generateKeys () {
const keyPair = sodium.crypto_sign_keypair()
this.publicKey = keyPair.publicKey
this.privateKey = keyPair.privateKey
}
encryptPassword (password) {
this.salt = sodium.randombytes_buf(this.keySettings.saltBytes)
this.password = sodium.crypto_pwhash(this.keySettings.keyLength, password, this.salt, this.keySettings.opslimit, this.keySettings.memlimit, this.keySettings.algorithm)
}
}
module.exports = Keys
......@@ -3,6 +3,7 @@ const sodium = require('libsodium-wrappers')
// Custom modules
const indexedDB = require('./indexedDB')
const Keys = require('./keys')
const form = document.getElementById('register')
......@@ -20,16 +21,10 @@ function loadedKeyPair () {
form.addEventListener('submit', (e) => {
e.preventDefault()
const password = e.target.password.value
const salt = sodium.randombytes_buf(sodium.crypto_pwhash_SALTBYTES)
const keyPair = sodium.crypto_sign_keypair()
console.log(keyPair)
const keyPair = new Keys()
keyPair.generateKeys()
keyPair.encryptPassword(password)
const keyLength = sodium.crypto_pwhash_BYTES_MIN
const opslimit = sodium.crypto_pwhash_OPSLIMIT_MAX
const memlimit = sodium.crypto_pwhash_MEMLIMIT_MAX
const algorithm = sodium.crypto_pwhash_ALG_DEFAULT
const encryptPassword = sodium.crypto_pwhash(keyLength, password, salt, opslimit, memlimit, algorithm)
const encryptedPrivateKey = sodium.crypto_pwhash(keyLength, keyPair.privateKey, encryptPassword, opslimit, memlimit, algorithm)
const postKeys = axios.post('register',
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment