Initial Lineups

This commit is contained in:
Jyotirmoy Bandyopadhayaya 2021-07-13 19:55:20 +05:30
parent 6d2994d571
commit 3c3d23c337
4 changed files with 65 additions and 3 deletions

View File

@ -1 +1,20 @@
console.log("Hello World")
const Cryptr = require("cryptr");
function Randomizer(secret) {
const ts = new Date().toUTCString();
if (!secret || typeof secret !== "string") {
throw new Error("Cryptr: secret must be a non-0-length string");
}
const cryptr = new Cryptr(secret);
const encryptedTs = cryptr.encrypt(ts);
console.log(encryptedTs);
this.showKey = function showKey() {
return secret;
};
this.getTs = function getTs() {
return ts;
};
}
module.exports = Randomizer;

View File

@ -4,7 +4,8 @@
"description": "A Random string encryptor w.r.t timestamp",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"hello": "echo hello world !!",
"test": "node ./test"
},
"repository": {
"type": "git",
@ -24,5 +25,17 @@
"bugs": {
"url": "https://github.com/bravo68web/randomizer/issues"
},
"homepage": "https://github.com/bravo68web/randomizer#readme"
"homepage": "https://github.com/bravo68web/randomizer#readme",
"dependencies": {
"crypto-js": "^4.0.0",
"cryptr": "^6.0.2",
"jose": "^3.14.0",
"randomstring": "^1.2.1",
"string-crypto": "^2.0.1",
"tape": "^5.2.2"
},
"devDependencies": {
"grunt": "^1.4.1",
"webpack": "^5.44.0"
}
}

20
test/index.js Normal file
View File

@ -0,0 +1,20 @@
const test = require("tape");
const Randomizer = require("../");
const testSecret = "myTotalySecretKey";
const testData = "bacon";
test("Initialization...", (t) => {
t.plan(1);
const Randomizr = new Randomizer(testSecret);
checkKey = Randomizr.showKey();
t.equal(checkKey, testSecret, "Key Mention can be Used");
});
test("Checking Timestamps...", (t) => {
t.plan(1);
const Randomizr = new Randomizer(testSecret);
var currentTs = new Date().toUTCString();
var innerTs = Randomizr.getTs();
t.equal(currentTs, innerTs, "TimeStamp Matched");
});

10
testBox.js Normal file
View File

@ -0,0 +1,10 @@
// console.log(new Date().toUTCString());
const Cryptr = require("cryptr");
const appEncryptKey =
"jWThgBwk4Awh7QQ82GDaz5QFcnVULu9Nk8bnU8sH6LcnfWfpeNaeYDLNGhSU47Yy";
const cryptr = new Cryptr(appEncryptKey);
currentTs = new Date().toUTCString();
const encryptedString = cryptr.encrypt(currentTs);
const decryptedString = cryptr.decrypt(encryptedString);
console.log(encryptedString);