Периписал на чистый web crypto api
This commit is contained in:
@@ -24,7 +24,6 @@
|
|||||||
"@angular/router": "^4.0.0",
|
"@angular/router": "^4.0.0",
|
||||||
"core-js": "^2.4.1",
|
"core-js": "^2.4.1",
|
||||||
"rxjs": "^5.1.0",
|
"rxjs": "^5.1.0",
|
||||||
"webcrypto": "^0.1.0",
|
|
||||||
"zone.js": "^0.8.4"
|
"zone.js": "^0.8.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
<span>Log Manager</span>
|
<span>Log Manager</span>
|
||||||
<span style="flex: 1 1 auto;"></span>
|
<span style="flex: 1 1 auto;"></span>
|
||||||
<span>
|
<span>
|
||||||
|
<button md-button (click)="GenerateKeyPair();">Ключ</button>
|
||||||
<button md-raised-button color="primary" (click)="AddNew();">Новый</button>
|
<button md-raised-button color="primary" (click)="AddNew();">Новый</button>
|
||||||
<button (click)="Exit();" md-raised-button color="warn">Выхода нет</button>
|
<button (click)="Exit();" md-raised-button color="warn">Выхода нет</button>
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { Http, Headers } from '@angular/http';
|
import { Http, Headers } from '@angular/http';
|
||||||
import * as crypto from 'webcrypto';
|
|
||||||
|
|
||||||
export class NewMessage {
|
export class NewMessage {
|
||||||
public Content: string;
|
public Content: string;
|
||||||
@@ -13,20 +12,6 @@ export class NewMessage {
|
|||||||
styleUrls: ['./app.component.css']
|
styleUrls: ['./app.component.css']
|
||||||
})
|
})
|
||||||
export class AppComponent {
|
export class AppComponent {
|
||||||
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;
|
showCon = false;
|
||||||
showDialog = false;
|
showDialog = false;
|
||||||
address = 'http://127.0.0.1:8000/api/';
|
address = 'http://127.0.0.1:8000/api/';
|
||||||
@@ -38,9 +23,6 @@ export class AppComponent {
|
|||||||
}
|
}
|
||||||
Decrypt(): void {
|
Decrypt(): void {
|
||||||
this.showCon = true;
|
this.showCon = true;
|
||||||
if (this.pass === 'genmekey') {
|
|
||||||
this.GenerateKeyPair();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
AddNew(): void {
|
AddNew(): void {
|
||||||
this.showDialog = true;
|
this.showDialog = true;
|
||||||
@@ -50,11 +32,42 @@ export class AppComponent {
|
|||||||
this.textarea = null;
|
this.textarea = null;
|
||||||
}
|
}
|
||||||
GenerateKeyPair(): void {
|
GenerateKeyPair(): void {
|
||||||
|
window.crypto.subtle.generateKey(
|
||||||
|
{
|
||||||
|
name: 'RSA-OAEP',
|
||||||
|
modulusLength: 4096, // can be 1024, 2048, or 4096
|
||||||
|
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
|
||||||
|
hash: {name: 'SHA-512'}, // can be "SHA-1", "SHA-256", "SHA-384", or "SHA-512"
|
||||||
|
},
|
||||||
|
true, // whether the key is extractable (i.e. can be used in exportKey)
|
||||||
|
['encrypt', 'decrypt'] // must be ["encrypt", "decrypt"] or ["wrapKey", "unwrapKey"]
|
||||||
|
)
|
||||||
|
.then(function(key){
|
||||||
|
// returns a keypair object
|
||||||
|
console.log(key);
|
||||||
|
console.log(key.publicKey);
|
||||||
|
console.log(key.privateKey);
|
||||||
|
window.crypto.subtle.exportKey(
|
||||||
|
'jwk', // can be "jwk" (public or private), "spki" (public only), or "pkcs8" (private only)
|
||||||
|
key.publicKey // can be a publicKey or privateKey, as long as extractable was true
|
||||||
|
)
|
||||||
|
.then(function(keydata){
|
||||||
|
// returns the exported key data
|
||||||
|
console.log(keydata);
|
||||||
|
});
|
||||||
|
window.crypto.subtle.exportKey(
|
||||||
|
'pkcs8', // can be "jwk" (public or private), "spki" (public only), or "pkcs8" (private only)
|
||||||
|
key.privateKey // can be a publicKey or privateKey, as long as extractable was true
|
||||||
|
)
|
||||||
|
.then(function(keydata){
|
||||||
|
// returns the exported key data
|
||||||
|
console.log(new Uint8Array(keydata));
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
AcceptNew(): void {
|
AcceptNew(): void {
|
||||||
console.log(this.textarea);
|
console.log(this.textarea);
|
||||||
console.log(this.pubkey);
|
const encrypted_text = this.textarea;
|
||||||
const encrypted_text = crypto.publicEncrypt(this.pubkey, this.textarea);
|
|
||||||
const obj = new NewMessage;
|
const obj = new NewMessage;
|
||||||
obj.Content = encrypted_text;
|
obj.Content = encrypted_text;
|
||||||
obj.Hash = '';
|
obj.Hash = '';
|
||||||
|
|||||||
Reference in New Issue
Block a user