Skip to content

VJAI/simple-crypto

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimpleCrypto

A PhoneGap plugin to encrypt strings using RNCryptor/JNCryptor (iOS/Android)

Usage

The plugin exposes two methods:

var rncryptor = cordova.require("com.disusered.simplecrypto.SimpleCrypto");

rncryptor.encrypt(key, data, successCallback, failureCallback)
rncryptor.decrypt(key, data, successCallback, failureCallback)

The parameters:

  • key: A string to use as your key.
  • data: A string representing data to encrypt or decrypt.
  • successHandler: Should be a function. Is called when the crypto operation is completed and is shown to the user.
  • failureHandler: Should be a function. Is called when there was a problem with the crypto operation.

Example usage

Useless cyclical example.

var rncryptor = cordova.require("com.disusered.simplecrypto.SimpleCrypto");

var key = 'myKey';

function failureCallback(error) {
    console.log('Error: ' + error);
}

function successCallback(encryptedData) {
    console.log('Encrypted data: ' + encryptedData);
    rncryptor.decrypt(key, encryptedData,
        function successCallback(decryptedData) {
            console.log('Decrypted data: ' + decryptedData);
        }, failureCallback);
}

rncryptor.encrypt(key, 'My data to encode', successCallback, failureCallback);

Usage with promises

Useless cyclical example.

var rncryptor = cordova.require("com.disusered.simplecrypto.SimpleCrypto");

var key = 'myKey';

function failureCallback(error) {
    console.log('Error: ' + error);
}

function successCallback(encryptedData) {
    console.log('Encrypted data: ' + encryptedData);
    rncryptor.decrypt(key, encryptedData,
        function successCallback(decryptedData) {
            console.log('Decrypted data: ' + decryptedData);
        }, failureCallback);
}

rncryptor.encrypt(key, 'My data to encode')
  .then(successCallback)
  .catch(failureCallback);

RNCryptor

iOS

This plugin uses the Objective-C implementation of RNCryptor. RNCryptor is a CCCryptor (AES encryption) wrapper for iOS and Mac. The data format includes all the metadata required to securely implement AES encryption. It is returned as a base64 string using NSData+Base64. The encrypted blob includes:

  • AES-256 encryption
  • CBC mode
  • Password stretching with PBKDF2
  • Password salting
  • Random IV
  • Encrypt-then-hash HMAC

Android

This plugin uses the Java implementation of RNCryptor, JNCryptor. JNCryptor is an easy-to-use library for encrypting data with AES. It was ported to Java from the RNCryptor library for iOS.

Todo

  • User defined key

About

Cordova plugin to encrypt/decrypt data

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published