Skip to content

Commit

Permalink
feat(aes256): Added new utility methods to generate secure key and se…
Browse files Browse the repository at this point in the history
…cure IV (#2675)
  • Loading branch information
pandiarajan-i2i authored and danielsogl committed Aug 31, 2018
1 parent d90724e commit a731466
Showing 1 changed file with 44 additions and 4 deletions.
48 changes: 44 additions & 4 deletions src/@ionic-native/plugins/aes-256/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,38 @@ import { Cordova, IonicNativePlugin, Plugin } from '@ionic-native/core';
* ```typescript
* import { AES256 } from '@ionic-native/aes-256';
*
*
* constructor(private aES256: AES256) { }
* private secureKey: string;
* private secureIV: string;
*
* constructor(private aes256: AES256) {
* this.generateSecureKeyAndIV(); // To generate the random secureKey and secureIV
* }
*
* ...
*
* async generateSecureKeyAndIV() {
* this.secureKey = await this.aes256.generateSecureKey('random password 12345'); // Returns a 32 bytes string
* this.secureIV = await this.aes256.generateSecureIV('random password 12345'); // Returns a 16 bytes string
* }
*
* this.aES256.encrypt('12345678123456781234567812345678', '1234567812345678', 'testdata')
* this.aes256.encrypt(this.secureKey, this.secureIV, 'testdata')
* .then(res => console.log('Encrypted Data: ',res))
* .catch((error: any) => console.error(error));
*
* this.aES256.decrypt('12345678123456781234567812345678', '1234567812345678', 'encryptedData')
* this.aes256.decrypt(this.secureKey, this.secureIV, 'encryptedData')
* .then(res => console.log('Decrypted Data : ',res))
* .catch((error: any) => console.error(error));
*
*
* * this.aes256.generateSecureKey('random password 12345')
* .then(res => console.log('Secure Key : ',res))
* .catch((error: any) => console.error(error));
*
*
* * this.aes256.generateSecureIV('random password 12345')
* .then(res => console.log('Secure IV : ',res))
* .catch((error: any) => console.error(error));
*
* ```
*/
@Plugin({
Expand Down Expand Up @@ -63,4 +81,26 @@ export class AES256 extends IonicNativePlugin {
return;
}

/**
* This function used to generate a secure key based on an password. Perfect if you want to delegate the key generation for encryption to the plugin.
* Make sure to save the return value of this function somewhere so your encrypted data can be decrypted in the future.
* @param {string} password A random string, which will be used as input for a PBKDF2 function
* @return {Promise<string>} Returns a promise that resolves when key is generated.
*/
@Cordova()
generateSecureKey(password: string): Promise<string> {
return;
}

/**
* This function used to generate a secure IV based on an password. Perfect if you want to delegate the IV generation for encryption to the plugin.
* Make sure to save the return value of this function somewhere so your encrypted data can be decrypted in the future.
* @param {string} password A random string, which will be used as input for a PBKDF2 function
* @return {Promise<string>} Returns a promise that resolves when IV is generated.
*/
@Cordova()
generateSecureIV(password: string): Promise<string> {
return;
}

}

0 comments on commit a731466

Please sign in to comment.