New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

cryptoaes

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cryptoaes

Cross Platform Encryption - Decryption with AES ( SHA-256 )

latest
Source
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

Crypto-Aes

Cross Platform SHA-256 bit AES Encryption - Decryption

Project contains the implementation SHA-256 bit AES encryption which works on stated platforms only. Easy use and implementation.

Platforms:

  • iOS ( not tested yet)

  • Android

  • Windows (C#). ( not tested yet )

  • Node.js

  • Web

Android Side

Just added Crypto.java file into your project and then add these functions.

Usage

//debug mode on
Crypto.DEBUG_LOG_ENABLED = true;

//key string must be max 32 char
String key = "0k8j7h6g5f4d3s2ak8j7h6g5f4d3s2a";

//iv string must be max 16 char
String iv = "0k8j7h6g5f4d3s2a";

//message string must be utf-8
String message = "hello world!!!";

//ecnrypted string
String encrypted = Crypto.encrypts(message,key,iv);

Log.d("Crypto",encrypted);

//decrypted string
String decrypted = Crypto.decrypts(encrypted,key,iv);

Log.d("Crypto",decrypted);

Web Side

Must be included cryptojs.js file into your project.

Functions

function getBytes(e){
  var bytes = [];
  for (var i = 0; i < e.length; ++i) {
    bytes.push(e.charCodeAt(i));
  }
  return bytes;
}

function getHex(e){
  return e.map(function(byte) {
    return ('0' + (byte & 0xFF).toString(16)).slice(-2);
  }).join('');
}

function hash(e){
  return CryptoJS.SHA256(e);
}

Usage

var message = "hello world!!!";
var iv = "0k8j7h6g5f4d3s2a";
var key = "0k8j7h6g5f4d3s2ak8j7h6g5f4d3s2a";


var iv1 = CryptoJS.enc.Hex.parse(getHex(getBytes(iv)));

console.log(iv1);

var cipher = CryptoJS.AES.encrypt(message, hash(key), {
    iv: iv1,
    mode: CryptoJS.mode.CBC,
    keySize: 256 / 32,
    padding: CryptoJS.pad.Pkcs7
});


var encrypted64 = cipher.ciphertext.toString(CryptoJS.enc.Base64);
console.log(encrypted64);

//decrypt
var bytes  = CryptoJS.AES.decrypt(encrypted64.toString(), hash(key), {
      iv: iv1,
      mode: CryptoJS.mode.CBC,
      keySize: 256 / 32,
      padding: CryptoJS.pad.Pkcs7
});

var plaintext = bytes.toString(CryptoJS.enc.Utf8);

console.log(plaintext);

Node.js Side

npm install cryptoaes

Usage

var Crypto = require("cryptoaes");

var message = "hello world!!!";
var iv = "0k8j7h6g5f4d3s2a";
var key = "0k8j7h6g5f4d3s2ak8j7h6g5f4d3s2a";

var r = Crypto.encrypts(message,key,iv);
console.log(r);
var r = Crypto.decrypts(r,key,iv);
console.log(r);

Do you want to donate ?

Support on Gratipay

Keywords

crypto , cross , platform , android , ios , mobile

FAQs

Package last updated on 26 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts