From ee6fecec5547c405e8b37d4f9db3044c4b614df7 Mon Sep 17 00:00:00 2001 From: Vlad Utkin Date: Thu, 18 May 2017 21:13:26 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=B1=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE=D1=82=D0=B5=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=BD=D0=B0=20webcrypto.=20=D0=9E=D1=88=D0=B8=D0=B1=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=BF=D1=80=D0=B8=20=D0=BF=D0=BE=D0=B4=D0=BF=D0=B8?= =?UTF-8?q?=D1=81=D0=B8=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/app/app.component.html | 1 - src/app/app.component.ts | 50 ++++++++++++++++++++------------------ 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index cba4ada..6e8126f 100644 --- a/package.json +++ b/package.json @@ -22,9 +22,9 @@ "@angular/platform-browser": "^4.0.0", "@angular/platform-browser-dynamic": "^4.0.0", "@angular/router": "^4.0.0", - "standard-ecies": "1.0.0", "core-js": "^2.4.1", "rxjs": "^5.1.0", + "webcrypto": "^0.1.0", "zone.js": "^0.8.4" }, "devDependencies": { diff --git a/src/app/app.component.html b/src/app/app.component.html index 1ec2ad8..3aa9414 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -2,7 +2,6 @@ Log Manager - diff --git a/src/app/app.component.ts b/src/app/app.component.ts index ad53683..342f4ca 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,11 +1,10 @@ import { Component } from '@angular/core'; -import { Http, Headers, Response } from '@angular/http'; -import * as crypto from 'crypto'; -import * as ecies from 'standard-ecies'; +import { Http, Headers } from '@angular/http'; +import * as crypto from 'webcrypto'; export class NewMessage { public Content: string; - public Sign: string; + public Hash: string; } @Component({ @@ -14,19 +13,20 @@ export class NewMessage { styleUrls: ['./app.component.css'] }) export class AppComponent { - cryptopt = { - hashName: 'sha256', - hashLength: '32', - macName: 'sha256', - macLength: '32', - curveName: 'secp256k1', - symmetricChyperName: 'aes-256-cbc', - iv: 6, - keyFormat: 'uncompressed', - s1: null, - s2: null - }; - ecdh = crypto.createECDH(this.cryptopt.curveName); + pubkey = '-----BEGIN PUBLIC KEY-----\n' + + 'AAAAB3NzaC1yc2EAAAABJQAAAgEAoGk22+PjQH4TEwT0v8qnYxm0YKcil4GB2j03\n' + + 'Ck5RamWid+TZGFH4aW0ekYe1aBB3Qt7FCs49zR3jxPpeQsv4AjehCB6AVU3R1rfL\n' + + '2ze+qiERUVFLcrYr1pzbABn/5YWwkPQFZlgPx82bOMCavDWCY9Z7xLmxeqcdP6P0\n' + + '7pbOe3UnIOSxPZblXvSHiYueAzL1o2bqaT2aJtF2yxuPQq/XDkBjAQ/kcOpVYr5Y\n' + + 'm9/5WwI8bBiipY+xLlXSa78TvVdoTZHdf7EIXZD0rGxmhxOT7KjO1QXycpprX7Yz\n' + + 'eOQVgc8W+B9fCkAaVaznNNo+wfVUUc5qp5urAz/OcF9X0AfjKjI9pXh6eqeipNA1\n' + + 'hBYeGrsxSOuTcd48t2OCQzt9213oj7PZEUImAnkXP3sYKykn2w2HseEzG9q/WszV\n' + + '3mENtPkApY7EapMfNV8wN0H7q8zZSv4AwkG3jhWKYgRfHURNMkx9jdnF2H+LbuH+\n' + + 'uyAh+SXDNuu8iEmMNrZBaUAVPJlqxX1O7i0t0XYiC509jdQvFIGI2FGVPXtudk5c\n' + + 'IXX0miZ8ZXUJHBKu/j/piWzejJTGHfdgBcA9gdnskZjgoNyBkU2adURMgkKwXA+n\n' + + 'Nb6WC+oxojn8RJGz127gwGGVgChX7h+uF2SL8m4C1AgBkV63CU9BNtRiAzZcCJhL\n' + + 'V+g5roU=\n' + + '-----END PUBLIC KEY-----'; showCon = false; showDialog = false; address = 'http://127.0.0.1:8000/api/'; @@ -50,17 +50,19 @@ export class AppComponent { this.textarea = null; } GenerateKeyPair(): void { - this.ecdh.generateKeys(); - console.log(this.ecdh.getPrivateKey()); - console.log(this.ecdh.getPublicKey()); } AcceptNew(): void { console.log(this.textarea); + console.log(this.pubkey); + const encrypted_text = crypto.publicEncrypt(this.pubkey, this.textarea); const obj = new NewMessage; - obj.Content = this.textarea; - obj.Sign = ''; + obj.Content = encrypted_text; + obj.Hash = ''; const body = JSON.stringify(obj); - const headers = new Headers({ 'Content-Type': 'application/json;charset=utf-8' }); - this.http.post((this.address + 'new'), body, { headers: headers }); + console.log(body); + const dejson = JSON.parse(body); + console.log(dejson); + // const headers = new Headers({ 'Content-Type': 'application/json;charset=utf-8' }); + // this.http.post((this.address + 'new'), body, { headers: headers }); } }