Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const mCrypt = require('mcrypt').MCrypt
- /*
- *encrypt police vehicle no
- *encrypt with algorithm rijndael-128, cbc
- *random key
- */
- function encrypt(value) {
- const theKey = getKey()
- const iv = '7yR83bkw5rpOGR4m'
- const encryptPoliceNo = new mCrypt('rijndael-128', 'cbc')
- encryptPoliceNo.validateKeySize(false)
- encryptPoliceNo.validateIvSize(false)
- encryptPoliceNo.open(theKey, iv)
- const cipherText = encryptPoliceNo.encrypt(value)
- const buf = Buffer.from(cipherText, 'utf8').toString('hex')
- return buf
- }
- function getKey() {
- const keyLength = 16
- const chars = '1234567890abcdefghijklmnopqrstuvwxyz'
- if (keyLength > 0) {
- const charLength = chars.length - 1
- let theKey = ''
- for (let idx = 1; idx < keyLength; idx = theKey.length) {
- theKey += chars.charAt(Math.floor(Math.random() * charLength))
- }
- return theKey
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement