funky-framadate-front/src/app/features/shared/components/ui/static-pages/ciphering/ciphering.component.ts

48 lines
1.4 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
const forge = require('node-forge');
@Component({
selector: 'app-ciphering',
templateUrl: './ciphering.component.html',
styleUrls: ['./ciphering.component.scss'],
})
export class CipheringComponent implements OnInit {
public plainText = 'le texte à chiffrer';
public cipheredText = '';
public salt = forge.random.getBytesSync(128);
public key = forge.random.getBytesSync(128);
public otherCipheredText: any;
constructor() {}
ngOnInit(): void {
this.encrypt(this.plainText);
}
encrypt(someText) {
// generate a random key and IV
// Note: a key size of 16 bytes will use AES-128, 24 => AES-192, 32 => AES-256
// const key = forge.random.getBytesSync(16);
// const iv = forge.random.getBytesSync(16);
/* alternatively, generate a password-based 16-byte key
var salt = forge.random.getBytesSync(128);
var key = forge.pkcs5.pbkdf2('password', salt, numIterations, 16);
*/
// encrypt some bytes using CBC mode
// (other modes include: ECB, CFB, OFB, CTR, and GCM)
// Note: CBC and ECB modes use PKCS#7 padding as default
// const cipher = forge.cipher.createCipher('AES-CBC', this.key);
// cipher.start({ iv: this.salt });
// cipher.update(forge.util.createBuffer(someText));
// cipher.finish();
// const encrypted = cipher.output;
// this.cipheredText = encrypted.toHex();
this.cipheredText = someText;
// outputs encrypted hex
console.log(this.cipheredText);
}
}