I am working on an android application, and I need to use encryption for one aspect of it. I am really indifferent to which algorithm I use (AES, DES, RSA, etc...). I am aware that Java has a crypto package, but I am not familiar with it at all. Can someone post an example on how to do an encrypt/decrypt function?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How can I create this custom Bottom Navigation on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
The
java AES
library has a flaw in it that allows, under the right circumstances, a listener to decrypt the packets sent. See Padding Oracle Exploit Tool vs Apache MyFaces.That being said check out this SO question Java 256bit AES Encryption.
Bouncy Castle AES EXAMPLE stolen from: http://www.java2s.com/Code/Java/Security/EncryptionanddecryptionwithAESECBPKCS7Padding.htm
Look at my answer here Android database encryption. It contains 2 files that you can include in any of your applications that require data storage to be encrypted.
Considering the overhead to encrypt and decrypt data in Android, I devised a library that relies only in Android and Java native libraries to make the process as simple as possible.
To install, use the jcenter distribuition center. On gradle:
compile 'com.tinmegali.android:mcipher:0.4'
Usage
MCipher is compatible from SDK 19+, and it automatically adapts itself to smaller and large chunks of data. By default, it uses
AES/GCM/NoPadding
for SDKs 23+, andRSA/ECB/PKCS1Padding
for older versions.MCipher on Github
I would also check out Conceal to see if it fits your bill. It has a easy to use API which abstracts the cryptographic details: https://github.com/facebook/conceal/