A simple fast encryption library for the JVM uses standard best practices and standard JVM classes
<dependency>
<groupId>com.github.gerritjvv</groupId>
<artifactId>crypto-core</artifactId>
<version>LATEST</version>
</dependency>
If you're not using an encryption key but directly using the user password, you must first run a key derivation routine on it.
byte[] pass = Key.deriveHmac256FromPass(null, "user-pass");
and then you can use:
byte[] key = Key.KeySize.AES_128.genKeysHmacSha(pass);
AES CBC encryption is HMACed and the result message contains
- version byte
- secure random iv
- hmac
- cipher message
import crypto.AES;
import crypto.Key;
import crypto.Util;
// generate some random data to encrypt
byte[] pass = crypto.Util.genData(4096);
byte[] someData = "Some Data".getBytes();
// generate encryption and authentication keys
Key.ExpandedKey key = Key.KeySize.AES_128.genKeysHmacSha(pass);
// encrypt the data
byte[] encryptedData = crypto.AES.encryptCBC(key, someData);
// decrypt it
byte[] decryptedData = crypto.AES.decryptCBC(key, encryptedData);
AES GCM encryption is authenticated (so no HMAC is required).
The result message contains:
- version byte
- secure random iv
- cipher message
import crypto.AES;
import crypto.Key;
import crypto.Util;
// generate some random data to encrypt
byte[] pass = crypto.Util.genData(4096);
byte[] someData = "Some Data".getBytes();
// generate encryption and authentication keys
Key.ExpandedKey key = Key.KeySize.AES_128.genKeysHmacSha(pass);
// encrypt the data
byte[] encryptedData = crypto.AES.encryptGCM(key, someData);
// decrypt it
byte[] decryptedData = crypto.AES.decryptGCM(key, encryptedData);
See: AESTest.java
https://www.apache.org/licenses/LICENSE-2.0
Contributions PRs and suggestions are always welcome.
Please ping me directly in the "issues" on "gerritjvv" or send me an email at gerritjvv@gmail.com, this way the issues/pull-requests won't just linger if github notifications doens't work.
https://dzone.com/articles/publish-your-artifacts-to-maven-central
Follow:
https://www.rainerhahnekamp.com/en/publishing-a-java-library-to-maven-central/
Repository staging is deployed to https://oss.sonatype.org