B4J Question Alice question (encryption)

wl

Well-Known Member
Licensed User
Longtime User
Hi,

I'm trying to encrypt an inputstream to an outputstream using @DonManfred 's library, but I 'm not sure how to do it.

B4X:
    Dim inp As InputStream = File.OpenInput("c:\temp", "inputFile.mp4")
    Dim outp As OutputStream = File.OpenOutput("c:\temp", "outputFile.mp4", False)

    Dim bc As ByteConverter
    Dim pwd() As Char = bc.CharsFromBytes(bc.StringToBytes("FGERHZXCG434TRWR", "ASCII"))

    Dim alice As Alice
    Dim ac As AliceConstants
    Dim bld As AliceContextBuilder
    bld.Initialize("")
    bld.Algorithm = ac.AES
    bld.Mode = ac.CTR

    alice.Initialize("Alice",bld.build)
    alice.encryptStream(inp, outp, pwd)

Returns: java.lang.IllegalArgumentException: Streaming encryption does not support authenticated encryption

As I found (https://github.com/rockaport/alice) should set MacAlgorithm to NONE, so I tried:

B4X:
    Dim inp As InputStream = File.OpenInput("c:\temp", "inputFile.mp4")
    Dim outp As OutputStream = File.OpenOutput("c:\temp", "outputFile.mp4", False)

    Dim bc As ByteConverter
    Dim pwd() As Char = bc.CharsFromBytes(bc.StringToBytes("FGERHZXCG434TRWR", "ASCII"))

    Dim alice As Alice
    Dim ac As AliceConstants
    Dim bld As AliceContextBuilder
    bld.Initialize("")
    bld.Algorithm = ac.AES
    bld.Mode = ac.CTR
    bld.MacAlgorithm = ac.MacAlgorithmNONE 'this is the line I added

    alice.Initialize("Alice",bld.build)
    alice.encryptStream(inp, outp, pwd)

Which returns: java.lang.IllegalArgumentException: No enum constant com.rockaport.alice.AliceContext.MacAlgorithm.None

I'm stuck now.

Another question: Is this way of encryption (and later: decryption) fast enough for large files/streams ?

Thanks
 

DonManfred

Expert
Licensed User
Longtime User
Returns: java.lang.IllegalArgumentException: Streaming encryption does not support authenticated encryption
looks like the settings are used for TEXT encryption. As i can see you are using the setting i used in my example to encrypt a String (not a Stream).

You may need to check the Alice Github project or google on how to setup a Stream-encryption.
Probably you need to setup the builder in a different way/with different settings.

I can´t help here as i do not have much experiences with Encryption. Never tried to encrypt a file.
 
Last edited:
Upvote 0
Top