From a49495ebef61c873b39fc4fab0202f9a50cde5f9 Mon Sep 17 00:00:00 2001 From: Wojciech Chodkowski Date: Thu, 22 Feb 2018 11:41:41 +0100 Subject: [PATCH] day 3 done --- app/prework.js | 25 +++++++++++++++++++++++++ app/zadanie01.js | 12 +++++++++++- app/zadanieDnia1.js | 15 ++++++++++++++- app/zadanieDnia2.js | 12 +++++++++++- 4 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 app/prework.js diff --git a/app/prework.js b/app/prework.js new file mode 100644 index 0000000..f0d3bc9 --- /dev/null +++ b/app/prework.js @@ -0,0 +1,25 @@ +const crypto = require('crypto'); + +const text = 'Hello World!'; +const hash = crypto.createHmac('sha256', text).digest('hex'); +console.log(hash); + +function encodeText(text, password, algorithm) { + const cipher = crypto.createCipher(algorithm, password); + + let encrypted = cipher.update(text, 'utf8', 'hex'); + encrypted += cipher.final('hex'); + return encrypted; +} + +console.log(encodeText('Hello, World!', 'M0j3 has|0!', 'aes-256-cbc')); + +function decodeText(encodedText, password, algorithm) { + const decipher = crypto.createDecipher(algorithm, password); + + let decrypted = decipher.update(encodedText, 'hex', 'utf8'); + decrypted += decipher.final('utf8'); + return decrypted; +} + +console.log(decodeText('352c9abb9cd20b41766f352b2611bb7b', 'M0j3 has|0!','aes-256-cbc')); diff --git a/app/zadanie01.js b/app/zadanie01.js index 842f75e..bbc8f43 100644 --- a/app/zadanie01.js +++ b/app/zadanie01.js @@ -1,3 +1,13 @@ const MY_PWD_HASH = '5dca0fc4e306d92b2077ad85e7c4bd87a3e8648e'; -//Twój kod \ No newline at end of file +const crypto =require('crypto'); + +const array= ['??TegoHasła','CodersLab','Node.js Szyfruje Pliki', 'Zaźółć Gęślą Jaźń','Moje Haslo 1@3!','111#$((@)n','Dzisiaj Szyfruje 83']; + +for(let i=0;i { + if(index > 1 ){ + fs.readFile(val, 'utf-8', (err, data)=> { + if(err === null) { + let hash = crypto.createHmac('sha256', data).digest('hex'); + console.log(hash); + } + }); + } +}); diff --git a/app/zadanieDnia2.js b/app/zadanieDnia2.js index 85846f4..44fa301 100644 --- a/app/zadanieDnia2.js +++ b/app/zadanieDnia2.js @@ -1,3 +1,13 @@ const ENCRYPTED_TEXT = '4f9fa8f98650091c4910f5b597773c0a48278cfb001fe4eb3ff47ada85cbf0ed3dc17016b031e1459e6e4d9b001ab6e102c11e834a98dce9530c9668c47b76ee6f09d075d19a38e48b415e067c6ddcfad0d3526c405a4f4f2fb1e7502f303c40'; -//Twój kod \ No newline at end of file +const crypto = require('crypto'); +//Twój kod +function decodeText(encodedText, password, algorithm) { + const decipher = crypto.createDecipher(algorithm, password); + + let decrypted = decipher.update(encodedText, 'hex', 'utf8'); + decrypted += decipher.final('utf8'); + return decrypted; +} + +console.log(decodeText(ENCRYPTED_TEXT, 'PysęjkkyDw','aes-256-ecb'));