GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - brianPlummer/AndroidEncryptionExample: Android RSA AES Example with unit tests

BranchesTags
Open more actions menu

Latest commit

 

History

64 Commits
64 Commits

Folders and files

NameName
Last commit message
Last commit date
app
app
 
 
assets
assets
 
 
gradle/wrapper
gradle/wrapper
 
 
.gitignore
.gitignore
 
 
README.md
README.md
 
 
build.gradle
build.gradle
 
 
gradle.properties
gradle.properties
 
 
gradlew
gradlew
 
 
gradlew.bat
gradlew.bat
 
 
license.txt
license.txt
 
 
settings.gradle
settings.gradle
 
 

Repository files navigation

Android Arsenal

Android Encryption Example

This example encrypts the inputted string using AES, encrypts the key via RSA, and does the reverse when the decrypt button is clicked.

We start by encrypting the plain text with AES

byte[] iv = AESEncryptDecrypt.aesEncrypt(plainTextInputStream,
                "secret key".toCharArray(),
                "AES/ECB/PKCS5PADDING",
                encOutputStream);

We then combine the outputted IV and the key we used:

byte[] combined = Util.concat("secret key".getBytes(), iv);

Lastly we encryt the IV and key using an RSA public key:

byte[] encryptedAESKeyIV = RSAEncryptDecrypt.encryptRSA(combined, rsaKey.getPublic());

========================

This is an encryption example of RSA and AES (CBC, ECB, CTR) 256 bit key on android with unit tests. I have tried to provide a good and secure example by showcasing:

  • AES 256 bit key
  • CBC/CTR/ECB example
  • using salt for key derivation
  • streams for arbitrary data sizes
  • unit tests
  • RSA 2048 bit
  • Spongy Castle (Android version of Bouncy Castle encryption library)

AndroidEncryptionExample

Prerequisite

In order to build the apk and run tests you must have the JCE (Java Cryptogrpahy Extension) Unlimited Strength policy jars installed for your JRE runtime.

  • JCE download for java 8: http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html

If you do not do this then you will see the error:

java.lang.RuntimeException: java.security.InvalidKeyException: Illegal key size or default parameters

Testing/Building

To run the unit tests

./gradlew clean test

To build and install apk:

./gradlew clean installDebug

About

Android RSA AES Example with unit tests

Topics

aesaes-256android-librarybouncy-castleecbencryptionencryptsrsasecurity

Resources

Readme
MIT license
Activity

Stars

75 stars

Watchers

7 watching

Forks

30 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.