Android encryption

前端 未结 4 1944
走了就别回头了
走了就别回头了 2020-11-29 19:48

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 awa

4条回答
  •  长情又很酷
    2020-11-29 20:28

    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

    String ALIAS = "alias"
    MEncryptor encryptor = new MEncryptorBuilder( ALIAS ).build();
    MDecryptor decryptor = new MDecryptorBuilder( ALIAS ).build();
    
    String toEncrypt = "encrypt this string";
    // encrypting
    String encrypted = encryptor.encryptString( toEncrypt, this );
    
    // decrypting
    String decrypted = decryptor.decryptString( encrypted, this );
    

    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+, and RSA/ECB/PKCS1Padding for older versions.

    MCipher on Github

提交回复
热议问题