mirror of
https://framagit.org/framasoft/framadate/funky-framadate-front.git
synced 2023-08-25 13:53:14 +02:00
easy ciphering working with and without salt
This commit is contained in:
parent
760bde7e30
commit
3e0c1ff375
@ -17,11 +17,6 @@
|
||||
.btn + .btn {
|
||||
margin-left: 1em;
|
||||
}
|
||||
.is-boxed {
|
||||
border: 1px solid #ddd;
|
||||
padding: 1em;
|
||||
margin: 1em 0;
|
||||
}
|
||||
|
||||
.cdk-drag-preview {
|
||||
box-sizing: border-box;
|
||||
|
@ -1,22 +1,69 @@
|
||||
<div class="ciphering padded">
|
||||
<h2>
|
||||
Test de chiffrement
|
||||
Essais de chiffrement pour un framadate zéro knoledge
|
||||
</h2>
|
||||
<br />
|
||||
<input type="text" [(ngModel)]="plainText" (ngModelChange)="encrypt(plainText)" />
|
||||
texte clair
|
||||
<br />
|
||||
<input type="text" [(ngModel)]="salt" />
|
||||
salt
|
||||
<br />
|
||||
<input type="text" [(ngModel)]="key" />
|
||||
pepper
|
||||
<div class="columns">
|
||||
<div class="column">
|
||||
<section class="boxed-shadow">
|
||||
<h3>Chiffrement simple</h3>
|
||||
<input type="text" [(ngModel)]="plainText" (ngModelChange)="encrypt(plainText)" />
|
||||
texte clair à convertir en truc indéchiffrable (à priori)
|
||||
|
||||
<br />
|
||||
<input type="text" [(ngModel)]="cipheredText" />
|
||||
texte chiffré
|
||||
<br />
|
||||
simple ciphered. On assigne un numéro à chaque caractère, séparé par un tiret en sortie.
|
||||
<strong class="cipher-result">
|
||||
<app-copy-text [textToCopy]="simpleCipheredText" [displayLabelButton]="false"></app-copy-text>
|
||||
{{ simpleCipheredText }}
|
||||
</strong>
|
||||
<br />
|
||||
<h3>Avec un peu de sel?</h3>
|
||||
<input type="text" [(ngModel)]="salt" />
|
||||
salt
|
||||
<br />
|
||||
simple ciphered avec un sel. on ajoute le sel avant le texte puis on passe le tout dans la conversion
|
||||
comme ci-dessus.
|
||||
<strong class="cipher-result">
|
||||
<app-copy-text
|
||||
[textToCopy]="simpleCipheredTextWithSalt"
|
||||
[displayLabelButton]="false"
|
||||
></app-copy-text>
|
||||
{{ simpleCipheredTextWithSalt }}
|
||||
</strong>
|
||||
</section>
|
||||
</div>
|
||||
<div class="column"></div>
|
||||
</div>
|
||||
|
||||
<br />
|
||||
<input type="text" [(ngModel)]="otherCipheredText" />
|
||||
texte à déchiffrer
|
||||
<section class="boxed-shadow">
|
||||
<h3>Déchiffrement simple</h3>
|
||||
|
||||
Collez ici le texte chiffré à convertir en truc lisible par l'opération
|
||||
<strike>du saint esprit</strike> réalisée dans l'autre sens
|
||||
<input type="text" [(ngModel)]="cipheredText" />
|
||||
<br />
|
||||
simple texte déchiffré
|
||||
<strong class="cipher-result">
|
||||
{{ simpleDeCipheredText }}
|
||||
</strong>
|
||||
simple texte déchiffré avec sel
|
||||
<strong class="cipher-result">
|
||||
{{ simpleDeCipheredTextWithSalt }}
|
||||
</strong>
|
||||
</section>
|
||||
|
||||
<section class="is-boxed">
|
||||
<h3>Chiffrement AES</h3>
|
||||
|
||||
<app-wip-todo></app-wip-todo>
|
||||
<input type="text" [(ngModel)]="cipheredText" />
|
||||
texte avancé à déchiffrer
|
||||
<br />
|
||||
<input type="text" [(ngModel)]="salt" />
|
||||
salt
|
||||
<input type="text" [(ngModel)]="initial_vector" />
|
||||
initial_vector
|
||||
<br />
|
||||
<input type="text" [(ngModel)]="key" />
|
||||
key
|
||||
</section>
|
||||
</div>
|
||||
|
@ -0,0 +1,18 @@
|
||||
.boxed-shadow {
|
||||
padding: 1em;
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
.cipher-result {
|
||||
border-radius: 3px;
|
||||
background: #00003b;
|
||||
color: #7d6c99;
|
||||
padding: 0.5em;
|
||||
margin-left: 1em;
|
||||
display: block;
|
||||
min-width: 10ch;
|
||||
min-height: 2em;
|
||||
max-width: 100%;
|
||||
overflow: hidden;
|
||||
line-height: 2em;
|
||||
}
|
@ -11,13 +11,15 @@ import * as Crypto from 'crypto';
|
||||
styleUrls: ['./ciphering.component.scss'],
|
||||
})
|
||||
export class CipheringComponent implements OnInit {
|
||||
public plainText = 'le texte à chiffrer, coucou !';
|
||||
public cipheredText = '';
|
||||
// public plainText = 'le texte à chiffrer, coucou !';
|
||||
public plainText = 'salut les pipole';
|
||||
public cipheredText =
|
||||
'121-127-42-110-127-42-122-121-115-128-124-111-125-107-118-127-126-42-118-111-125-42-122-115-122-121-118-111';
|
||||
algorithm = 'aes-192-cbc';
|
||||
// public salt = Crypto.randomBytes(16);
|
||||
// public initial_vector = Crypto.randomBytes(16);
|
||||
public salt = 'ou du poivre';
|
||||
public initial_vector = '';
|
||||
public key;
|
||||
public otherCipheredText: any;
|
||||
public otherCipheredText = 'le texte à chiffrer, coucou !';
|
||||
|
||||
constructor() {}
|
||||
|
||||
@ -25,6 +27,21 @@ export class CipheringComponent implements OnInit {
|
||||
this.encrypt(this.plainText);
|
||||
}
|
||||
|
||||
// ---------------------- make unreadable ----------------------
|
||||
get simpleCipheredText() {
|
||||
return this.convertTextToInt(this.plainText);
|
||||
}
|
||||
get simpleCipheredTextWithSalt() {
|
||||
return this.convertTextToInt(this.salt + this.plainText);
|
||||
}
|
||||
// ---------------------- make readable ----------------------
|
||||
get simpleDeCipheredText() {
|
||||
return this.convertIntToText(this.cipheredText);
|
||||
}
|
||||
get simpleDeCipheredTextWithSalt() {
|
||||
return this.convertIntToText(this.salt + this.cipheredText);
|
||||
}
|
||||
// ---------------------- conversions ----------------------
|
||||
encrypt(someText) {
|
||||
// this.key = Crypto.scryptSync(someText, 'salt', 24);
|
||||
// this.initial_vector = Crypto.randomBytes(16);
|
||||
@ -40,6 +57,7 @@ export class CipheringComponent implements OnInit {
|
||||
// this.cipheredText = someText;
|
||||
// // outputs encrypted hex
|
||||
// console.log(this.cipheredText);
|
||||
return someText;
|
||||
}
|
||||
|
||||
decrypt(sometext) {
|
||||
@ -53,14 +71,29 @@ export class CipheringComponent implements OnInit {
|
||||
//
|
||||
// decipher.write(sometext, 'hex');
|
||||
// decipher.end();
|
||||
return sometext;
|
||||
}
|
||||
|
||||
convertTextToInt(someText) {
|
||||
let output = '';
|
||||
|
||||
for (let i = 0; i < someText.length; i++) {
|
||||
output += someText[i].charCodeAt(0);
|
||||
convertTextToInt(value) {
|
||||
let result = '';
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
if (i < value.length - 1) {
|
||||
result += value.charCodeAt(i) + 10;
|
||||
result += '-';
|
||||
} else {
|
||||
result += value.charCodeAt(i) + 10;
|
||||
}
|
||||
}
|
||||
return output;
|
||||
return result;
|
||||
}
|
||||
convertIntToText(value) {
|
||||
let result = '';
|
||||
const array = value.split('-');
|
||||
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
result += String.fromCharCode(array[i] - 10);
|
||||
}
|
||||
// remove salt characters
|
||||
return result.slice(this.salt.length);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user