Coder Social home page Coder Social logo

rockaport / alice Goto Github PK

View Code? Open in Web Editor NEW
78.0 8.0 15.0 192 KB

Java AES encryption library

Home Page: https://rockaport.github.io/alice/

License: Apache License 2.0

Java 100.00%
encryption aes-encryption pbkdf2 java-library android-library android-encryption android-aes file-encryption byte-encryption

alice's People

Contributors

rockaport avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

alice's Issues

java.security.InvalidKeyException: Illegal key size

Hi guys, I'm following the tutorial, and here is my code

Alice alice = new Alice(new AliceContextBuilder().build());
byte[] encryptedBytes = alice.encrypt("hello".getBytes(), "password".toCharArray());

However I got this error message. ?

java.security.InvalidKeyException: Illegal key size

	at javax.crypto.Cipher.checkCryptoPerm(Cipher.java:1039)
	at javax.crypto.Cipher.implInit(Cipher.java:805)
	at javax.crypto.Cipher.chooseProvider(Cipher.java:864)
	at javax.crypto.Cipher.init(Cipher.java:1396)
	at javax.crypto.Cipher.init(Cipher.java:1327)
	at com.rockaport.alice.Alice.encrypt(Alice.java:177)
	at com.netobjex.ubc.service.IPFSServiceTest.setup(IPFSServiceTest.java:56)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

PBKDF2WithHmacSHA512 Encryption example

KeySpec ks = new PBEKeySpec(mnemonic, salt, 2048, 512);
SecretKeyFactory skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA512");
return skf.generateSecret(ks).getEncoded();

Hey @rockaport, what might this code look like using alice?

Encryption output

Hi,
I want to use your library in a project of mine and I need to get the encrypted output as a string with UTF-8 format. Is that possible?
I use that:
AliceContext aliceContext = new AliceContextBuilder() .setAlgorithm(AliceContext.Algorithm.AES) .setMode(AliceContext.Mode.CBC) // or AliceContext.Mode.CTR .setIvLength(16) .setPadding(AliceContext.Padding.PKCS5_PADDING) .setPbkdf(AliceContext.Pbkdf.PBKDF_2_WITH_HMAC_SHA_512) .setMacAlgorithm(AliceContext.MacAlgorithm.HMAC_SHA_512) .build();
And to get the output I use that:
byte[] d = alice.encrypt(toEncrypt.getBytes(), secretKey.toCharArray()); System.out.println(new String(d)); System.out.println(new String(alice.decrypt(d, secretKey.toCharArray())));
But the output looks like:
�8Ӥ�Öz�>�$���� B�+4�\kLA{�R�a Bŋ����֒b�\ا� �]j�.���?�r�$j"RɫIܪ���C��>p���~�L�]���� ����\��R3;!p�.��T������Ѫ&�r ��TK<{>A�HN�?�07�nϳ�U�ؑ�<X������j�����YA<K�dы�BP+9�
Do you have an idea to get an output that is sharable?

Why have a dependency on okio?

You literally only use it in one place and it is EASILY replaced with a ByteArrayOutputStream.

I rewrote your the last part of your encrypt() method to not use any dependencies:

ByteArrayOutputStream output = new ByteArrayOutputStream();
    try {
      output.write(cipher.getIV());
      output.write(encryptedBytes);

      // compute the MAC if needed and append the MAC (IV || CIPHER || MAC)
      if (context.getMacAlgorithm() != AliceContext.MacAlgorithm.NONE) {
        output.write(getMac(context.getMacAlgorithm(), password).doFinal(encryptedBytes));
      }
    } catch (IOException e) {
      throw new RuntimeException(e);
    }

    return output.toByteArray();

Gives the following error on android studio 3.0.1

Having it added in gradle,on run the following error is given:
`Information:Gradle tasks [:app:assembleDebug]
Warning:Ignoring InnerClasses attribute for an anonymous inner class
Error:com.android.builder.dexing.DexArchiveBuilderException: Failed to process /Users/nimashahbazi/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy-all/2.4.1/a9ca9c9de09361ec2a18d2c058d2524fbd8eae0c/groovy-all-2.4.1.jar
Error:com.android.builder.dexing.DexArchiveBuilderException: Error while dexing org/codehaus/groovy/vmplugin/v7/IndyInterface.class
Error:com.android.dx.cf.code.SimException: signature-polymorphic method called without --min-sdk-version >= 26
Error:Execution failed for task ':app:transformClassesWithDexBuilderForDebug'.

com.android.build.api.transform.TransformException: com.android.builder.dexing.DexArchiveBuilderException: com.android.builder.dexing.DexArchiveBuilderException: Failed to process /Users/nimashahbazi/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy-all/2.4.1/a9ca9c9de09361ec2a18d2c058d2524fbd8eae0c/groovy-all-2.4.1.jar
Information:BUILD FAILED in 10s
Information:4 errors
Information:1 warning
Information:See complete output in console`

Any ideas? Thanks

Zip file gets corrupted after encryption...

I have been trying to encrypt a zip file using different algorithms presented in the library. The file is encrypted and decrypted and when I try to to unzip it, seems like the file is corrupted...
I have tried many compression tools and seems like this is happening because of the encryption process. Have you ever faced anything like that and any ideas on what needs to be done?

alice:0.9.0 Error on Android Studio 3.3.2

When I add the following line to gradle
implementation 'com.github.rockaport:alice:0.9.0'
and building the project , I encounter the following error
Error: MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26).

what is the problem?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.