Encryption is a simple way to encrypt and decrypt strings on Android and Java project.
MIT License
Encryption is a simple way to encrypt and decrypt strings on Android and Java project.
1 Add JitPack to your build file
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
2 Add the gradle dependency
compile 'com.github.simbiose:Encryption:2.0.1'
3 Get an Encryption instance
String key = "YourKey";
String salt = "YourSalt";
byte[] iv = new byte[16];
Encryption encryption = Encryption.getDefault(key, salt, iv);
4 Encrypt your text
String encrypted = encryption.encryptOrNull("Text to be encrypt");
5 Decrypt your text
String decrypted = encryption.decryptOrNull(encrypted);
You can use you own builder
Encryption encryption = new Encryption.Builder()
.setKeyLength(128)
.setKey("YourKey")
.setSalt("YourSalt")
.setIv(yourByteIvArray)
.setCharsetName("UTF8")
.setIterationCount(1)
.setDigestAlgorithm("SHA1")
.setBase64Mode(Base64.DEFAULT)
.setAlgorithm("AES/CBC/PKCS5Padding")
.setSecureRandomAlgorithm("SHA1PRNG")
.setSecretKeyType("PBKDF2WithHmacSHA1")
.build();
See more on Examples folder, there is an Android, a Java and a Kotlin project.
yourByteIvArray
byte[] iv = {-89, -19, 17, -83, 86, 106, -31, 30, -5, -111, 61, -75, -84, 95, 120, -53};
like you can see, 16 bytes in a byte array. So if you want to use this library I recommend you create you own IV and save it 💾.encryptOrNull
method just uses the encrypt
method. The same for the decryptOrNull
, just uses the decrypt
method.encryptAsync
with a Encryption.Callback
to avoid ANR'S. The same for decryptAsync
Builder
manually to the same parameters used in version 1.1 and olds.Fell free to contribute, We really like pull requests :octocat: