@@ -16,6 +16,9 @@ Easily encrypt, decrypt, or hash data in a very secure way.
1616* Supports MD5, SHA1, and SHA2 hash functions
1717* SecureRandom fixes on Android below KitKat
1818* Generate key manually with SecureRandom or random.org
19+ * Asymmetric encryption with RSA
20+ * Auto handle large data by using hybrid asymmetric encryption
21+ * Supported RSA key sizes are 2048 bits and 4096 bits
1922
2023## Install in Java app
2124Add in your project's build.gradle
@@ -37,7 +40,7 @@ apply plugin: 'kotlin-android-extensions'
3740
3841dependencies {
3942 ...
40- compile "com.pvryan.easycrypt:easycrypt:1.0.6 "
43+ compile "com.pvryan.easycrypt:easycrypt:1.1.0 "
4144 compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.3-2"
4245 compile "org.jetbrains.anko:anko-commons:0.10.1"
4346 ...
@@ -49,18 +52,20 @@ Add in your app's build.gradle
4952``` gradle
5053dependencies {
5154 ...
52- compile "com.pvryan.easycrypt:easycrypt:1.0.6 "
55+ compile "com.pvryan.easycrypt:easycrypt:1.1.0 "
5356 ...
5457}
5558```
5659
5760## Usage
5861``` kotlin
5962val eCryptSymmetric = ECryptSymmetric ()
63+ val eCryptAsymmetric = ECryptAsymmetric ()
6064val eCryptHash = ECryptHash ()
6165val eCryptPass = ECryptPasswords ()
6266```
6367
68+ ### Symmetric key encryption
6469#### Encrypt data
6570``` kotlin
6671eCryptSymmetric.encrypt (input, password,
@@ -105,6 +110,62 @@ eCryptSymmetric.decrypt(input, password,
105110)
106111```
107112
113+ ### Asymmetric key encryption
114+ #### Encrypt data
115+ ``` kotlin
116+ eCryptAsymmetric.generateKeyPair(object : ECryptRSAKeyPairListener {
117+
118+ override fun onSuccess (keyPair : KeyPair ) {
119+ privateKey = keyPair.private as RSAPrivateKey // Save private key
120+ eCryptAsymmetric.encrypt(input, keyPair.public as RSAPublicKey ,
121+ object : ECryptResultListener {
122+
123+ // Optional
124+ override fun onProgress (newBytes : Int , bytesProcessed : Long ) {
125+
126+ }
127+
128+ override fun <T > onSuccess (result : T ) {
129+
130+ }
131+
132+ override fun onFailure (message : String , e : Exception ) {
133+
134+ }
135+ },
136+ outputFile // Optional
137+ )
138+ }
139+
140+ override fun onFailure (message : String , e : Exception ) {
141+ e.printStackTrace()
142+ }
143+
144+ }, keySize = eCryptAsymmetric.KeySizes ._4096 )
145+ ```
146+
147+ #### Decrypt data
148+ ``` kotlin
149+ eCryptAsymmetric.decrypt(input, privateKey,
150+ object : ECryptResultListener {
151+
152+ // Optional
153+ override fun onProgress (newBytes : Int , bytesProcessed : Long ) {
154+
155+ }
156+
157+ override fun <T > onSuccess (result : T ) {
158+
159+ }
160+
161+ override fun onFailure (message : String , e : Exception ) {
162+
163+ }
164+ },
165+ outputFile // Optional
166+ )
167+ ```
168+
108169#### Hash data
109170``` kotlin
110171eCryptHash.calculate(input, hashAlgorithm, // from ECryptHashAlgorithms
@@ -127,14 +188,16 @@ eCryptHash.calculate(input, hashAlgorithm, // from ECryptHashAlgorithms
127188)
128189```
129190
130- ------------------------------------------------------
131- | Input | Output |
132- | -----------------| ----------------------------------|
133- | File | outputFile |
134- | FileInputStream | outputFile |
135- | ByteArray | String (outputFile, if provided) |
136- | String | String (outputFile, if provided) |
137- | CharSequence | String (outputFile, if provided) |
191+ --------------------------------------------------------------
192+ | Input | Output |
193+ | -----------------------| ------------------------------------|
194+ | File | outputFile |
195+ | FileInputStream | outputFile |
196+ | ByteArray | String or outputFile (if provided) |
197+ | ByteArrayInputStream | String or outputFile (if provided) |
198+ | String | String or outputFile (if provided) |
199+ | CharSequence | String or outputFile (if provided) |
200+ | Anything else | InvalidParameterException |
138201
139202#### Generate key with SecureRandom (pseudo-random)
140203``` kotlin
0 commit comments