Coder Social home page Coder Social logo

aes-256-encryption-utility's Introduction

Run | How To Use | Generate AES-256 Key | View AES-256 Key | Command Line Encrypt/Decrypt

Overview:

This is a sample utility to encrypt/decrypt using AES/CBC/PKCS5Padding algorithm

Most common error: "Invalid Key Size" error is most likely caused by not updating JCE strength policy, see above

NOTE: This example is built using JDK7, ultimate strength JCE (JDK7) and Maven 3.x

To Run:

mvn clean test

Run | How To Use | Generate AES-256 Key | View AES-256 Key | Command Line Encrypt/Decrypt

To Use:

# Key stored in JCEKS formatted Java keystore
Key key = ....; // see tests pulling key from keystore
// alternative is to hard-code key in string
AESCipher cipher = new AESCipher(key);

String encryptedMessage = cipher.getEncryptedMessage("this is message");
String decryptedMessage = cipher.getDecryptedMessage(encryptedMessage);

AESCipher cipherWithIv = new AESCipher(key, "0123456789012345".getBytes());
String encryptedMessage = cipherWithIv.getEncryptedMessage("this is message");
String decryptedMessage = cipherWithIv.getDecryptedMessage(encryptedMessage);

Run | How To Use | Generate AES-256 Key | View AES-256 Key | Command Line Encrypt/Decrypt

Generate an AES-256 Key

keytool -genseckey -alias jceksaes -keyalg AES -keysize 256 -storetype JCEKS -keypass mykeypass -storetype jceks -keystore aes-keystore.jck -storepass mystorepass

Run | How To Use | Generate AES-256 Key | View AES-256 Key | Command Line Encrypt/Decrypt

View AES-256 Key from command line

mvn clean package // generate executable JAR file
java -Dkeystore=main-aes-keystore.jck -Dstorepass=mystorepass -Dalias=jceksaes -Dkeypass=mykeypass -jar target/example-encryption-util.jar <COMMAND like 'showKey'>

// or optionally with Maven (using the above defaults)
mvn exec:java

Run | How To Use | Generate AES-256 Key | View AES-256 Key | Command Line Encrypt/Decrypt

Encrypt/Decrypt AES-256 from command line

// Generate executable JAR with:  mvn package

// Ideally the IV passed in (0000000000000000) would be randomly generated
java -Dkeystore=main-aes-keystore.jck -Dstorepass=mystorepass -Dalias=jceksaes -Dkeypass=mykeypass -jar target/example-encryption-util.jar encrypt blahblahblah 0000000000000000
java -Dkeystore=main-aes-keystore.jck -Dstorepass=mystorepass -Dalias=jceksaes -Dkeypass=mykeypass -jar target/example-encryption-util.jar decrypt baN3CIAcVgq+AQr7lvKmLw== 0000000000000000


java -Dkeystore=main-aes-keystore.jck -Dstorepass=mystorepass -Dalias=jceksaes -Dkeypass=mykeypass -jar target/example-encryption-util.jar encrypt blahblahblah 0000000000000001
java -Dkeystore=main-aes-keystore.jck -Dstorepass=mystorepass -Dalias=jceksaes -Dkeypass=mykeypass -jar target/example-encryption-util.jar decrypt Wcaov8LNN4GJvp1bvOTJ0g== 0000000000000001

Run | How To Use | Generate AES-256 Key | View AES-256 Key | Command Line Encrypt/Decrypt

Copywrite ©2013 - Use of this code and it's concepts are considered a Proof-of-concept and should not be used directly in any environment

aes-256-encryption-utility's People

Contributors

mike-ensor avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.