From 4623d56ccab5213037f611e6495359d18a51f30d Mon Sep 17 00:00:00 2001 From: Vlad Utkin Date: Wed, 24 May 2017 23:49:30 +0300 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=BB=D0=BE=20AES-256-CBC=20=D1=88=D0=B8=D1=84=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/app/app.component.ts | 9 ++++----- src/app/app.module.ts | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 8a73f86..5256656 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "@angular/router": "^4.0.0", "@types/crypto-js": "^3.1.33", "core-js": "^2.4.1", - "cryptojs": "^2.5.3", + "crypto-js": "^3.1.9-1", "rxjs": "^5.1.0", "zone.js": "^0.8.4" }, diff --git a/src/app/app.component.ts b/src/app/app.component.ts index c967a5e..e148227 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,6 +1,6 @@ import { Component } from '@angular/core'; import { Http, Headers } from '@angular/http'; -import { AES, SHA256 } from 'cryptojs'; +import * as CryptoJS from 'crypto-js'; export class NewMessage { public Content: string; @@ -32,15 +32,14 @@ export class AppComponent { this.showDialog = false; this.textarea = null; } - GenerateKeyPair(): void { - } AcceptNew(): void { console.log(this.textarea); - const encrypted_text = AES(this.textarea, this.pass); + const encrypted_text = CryptoJS.AES.encrypt(this.textarea, this.pass); const obj = new NewMessage; - obj.Content = encrypted_text; + obj.Content = encrypted_text.toString(); const body = JSON.stringify(obj); console.log(body); + console.log(CryptoJS.AES.decrypt(obj.Content, this.pass).toString(CryptoJS.enc.Utf8)); // const headers = new Headers({ 'Content-Type': 'application/json;charset=utf-8' }); // this.http.post((this.address + 'new'), body, { headers: headers }); } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index fcf57fe..0b4fd75 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -6,7 +6,7 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { MdButtonModule, MdCheckboxModule, MdToolbarModule, MdSidenavModule, MdCardModule} from '@angular/material'; import { AppComponent } from './app.component'; -import { MdInputModule } from "@angular/material"; +import { MdInputModule } from '@angular/material'; @NgModule({ declarations: [