B4A Library Alice - AES Encryption

This is a wrap for this Github Project.

Java AES encryption library

Alice is a Java AES/DES encryption library for working with byte arrays, files, and streams. Various key lengths, block modes, padding schemes, key deriviation functions, and Message Authentication Codes (MAC) are available. See the javadoc for more information.


Alice
<link>Aliceproject on Github|https://github.com/rockaport/alice</link>
Author: DonManfred
Version: 0.07
  • Alice
    • Events:
      • Decrypt (success As Boolean, path As String, Filename As String)
      • Encrypt (success As Boolean, path As String, Filename As String)
    • Functions:
      • decryptBytes (encrypted As Byte(), password As String) As Byte()
      • decryptFile (sourcePath As String, sourceFilename As String, destPath As String, destFilename As String, password As String)
      • decryptFile2 (sourcePath As String, sourceFilename As String, destPath As String, destFilename As String, password As String)
      • decryptStream (input As java.io.InputStream, output As java.io_OutputStream, password As Char())
      • encryptBytes (input As Byte(), password As Char()) As Byte()
      • encryptFile (sourcePath As String, sourceFilename As String, destPath As String, destFilename As String, password As String)
      • encryptFile2 (sourcePath As String, sourceFilename As String, destPath As String, destFilename As String, password As String)
      • encryptStream (input As java.io.InputStream, output As java.io_OutputStream, password As Char())
      • generateKey (algorithm As String, keyLength As String) As Byte()
        algorithm can be either AES, DES or DESede
        keyLength can be either BITS_64, BITS_128, BITS_192 pr BITS_256
      • generateKey2 (algorithm As String, keyLength As String) As Byte()
      • Initialize (EventName As String, context As com.rockaport.alice.AliceContext)
  • AliceConstants
    • Fields:
      • AES As com.rockaport.alice.AliceContext.Algorithm
      • CBC As com.rockaport.alice.AliceContext.Mode
      • CTR As com.rockaport.alice.AliceContext.Mode
      • DES As com.rockaport.alice.AliceContext.Algorithm
      • DESede As com.rockaport.alice.AliceContext.Algorithm
      • GCM As com.rockaport.alice.AliceContext.Mode
      • GcmTagLengthBITS_104 As com.rockaport.alice.AliceContext.GcmTagLength
      • GcmTagLengthBITS_112 As com.rockaport.alice.AliceContext.GcmTagLength
      • GcmTagLengthBITS_120 As com.rockaport.alice.AliceContext.GcmTagLength
      • GcmTagLengthBITS_128 As com.rockaport.alice.AliceContext.GcmTagLength
      • GcmTagLengthBITS_96 As com.rockaport.alice.AliceContext.GcmTagLength
      • HMAC_SHA_1 As com.rockaport.alice.AliceContext.MacAlgorithm
      • HMAC_SHA_256 As com.rockaport.alice.AliceContext.MacAlgorithm
      • HMAC_SHA_384 As com.rockaport.alice.AliceContext.MacAlgorithm
      • HMAC_SHA_512 As com.rockaport.alice.AliceContext.MacAlgorithm
      • KeyLengthBITS_128 As com.rockaport.alice.AliceContext.KeyLength
      • KeyLengthBITS_192 As com.rockaport.alice.AliceContext.KeyLength
      • KeyLengthBITS_256 As com.rockaport.alice.AliceContext.KeyLength
      • KeyLengthBITS_64 As com.rockaport.alice.AliceContext.KeyLength
      • MacAlgorithmNONE As com.rockaport.alice.AliceContext.MacAlgorithm
      • PaddingNO_PADDING As com.rockaport.alice.AliceContext.Padding
      • PaddingPKCS5_PADDING As com.rockaport.alice.AliceContext.Padding
      • PBKDF_2_WITH_HMAC_SHA_1 As com.rockaport.alice.AliceContext.Pbkdf
      • PBKDF_2_WITH_HMAC_SHA_256 As com.rockaport.alice.AliceContext.Pbkdf
      • PBKDF_2_WITH_HMAC_SHA_384 As com.rockaport.alice.AliceContext.Pbkdf
      • PBKDF_2_WITH_HMAC_SHA_512 As com.rockaport.alice.AliceContext.Pbkdf
      • PbkdfNONE As com.rockaport.alice.AliceContext.Pbkdf
      • SHA_1 As com.rockaport.alice.AliceContext.Pbkdf
      • SHA_224 As com.rockaport.alice.AliceContext.Pbkdf
      • SHA_256 As com.rockaport.alice.AliceContext.Pbkdf
      • SHA_384 As com.rockaport.alice.AliceContext.Pbkdf
      • SHA_512 As com.rockaport.alice.AliceContext.Pbkdf
  • AliceContextBuilder
    • Functions:
      • build As com.rockaport.alice.AliceContext
      • Initialize (EventName As String)
      • IsInitialized As Boolean
    • Properties:
      • Algorithm As String [write only]
      • GcmTagLength As String [write only]
      • Iterations As Int [write only]
      • IvLength As Int [write only]
      • KeyLength As String [write only]
      • MacAlgorithm As String [write only]
      • Mode As String [write only]
      • Padding As String [write only]
      • Pbkdf As String [write only]

A B4J Version is also available.

I tested it with a file of 2.4GB Size
 

Attachments

  • AliceV0.07.zip
    23.3 KB · Views: 324
  • AliceV0.08.zip
    8.5 KB · Views: 408

noeleon

Active Member
Licensed User
Hi.

Can you please show me how to encrypt an array of bytes?

I tried but can't figure out how to initalize things.

Thanks.
 

DonManfred

Expert
Licensed User
Longtime User
Can you please show me how to encrypt an array of bytes?
1. You should never post in an existing thread. Always start a new thread for your question(s) in the questionsforum.
2. Update to v0.08

B4X:
        Dim strtoencrypt As String = "String to encrypt... bla bla bla"
        Dim password As String = "FGERHZXCG434TRWR"
        Dim encrypted() As Byte = alice.encryptBytes(strtoencrypt.GetBytes("UTF8"),password)
        Log(bc.HexFromBytes(encrypted))
       '
       ' And decrypting ....
       '
       Dim decrypted() As Byte = alice.decryptBytes(encrypted,password)
       Log(bc.StringFromBytes(decrypted,"UTF8"))
 
Last edited:
Top