rsa encryption and decryption by android
add to build.gradle,${latest.version} is
dependencies {
compile 'com.blakequ.rsa:rsa:${latest.version}'
}
maven
<dependency>
<groupId>com.blakequ.rsa</groupId>
<artifactId>rsa</artifactId>
<version>${latest.version}</version>
<type>pom</type>
</dependency>
you can download example and study how to use
For server code, you can find in example:com/blakequ/rsademo/javalib
FileEncryptionManager mFileEncryptionManager = FileEncryptionManager.getInstance();
//1.you can use generate public and private key
mFileEncryptionManager.generateKey();
//you can invoke getPublickey() and getPrivateKey() to save key to local file
//or 2.set public key and private key by youself(not use auto generate key)
mFileEncryptionManager.setRSAKey(String publicKey, String privateKey);
mFileEncryptionManager.setRSAKey(RSAPublicKey publicKey, RSAPrivateKey privateKey)
byte[] data = FileUtils.getBytesFromInputStream(getResources().getAssets().open("*.txt"));
//from byte array
byte[] result = mFileEncryptionManager.encryptFileByPublicKey(data, saveEncryFile);
//or from file
byte[] result = mFileEncryptionManager.encryptFileByPublicKey(ogirialFile, saveEncryFile);
byte[] result = mFileEncryptionManager.decryptFileByPrivateKey(encryFile, decryFile);
byte[] result = mFileEncryptionManager.decryptFileByPrivateKey(encryByteData, decryFile);