Skip to content

Could you please support AES256/CBC/PKCS7Padding? #33

Open

Description

@VincentChen1212

HI

This is a good Project.

and
Is this Project Support AES256/CBC/PKCS7Padding ???
or something can reference ??

Thanks

Activity

  1. changed the title [-] Support AES256/CBC/PKCS7Padding ???[/-] [+] Support AES256/CBC/PKCS7Padding ?[/+] on Aug 28, 2019
  2. BruceWind commented on Aug 28, 2019

    @BruceWind
    Owner

    Thanx for your issue.
    Im going to add some algorithms in few weeks.
    I have a lot of plan ,but Im too lazy. sorry.

  3. BruceWind commented on Aug 28, 2019

    @BruceWind
    Owner

    Hi ,man:
    i wasn’t lazy today. i made the repo -> https://github.com/BruceWind/CryptoPPInNDK.

    some algoritms will soon.

  4. VincentChen1212 commented on Aug 29, 2019

    @VincentChen1212
    Author

    Hi my Hero,

    Many Many Many Many Many Thanks, I Very Need AES256/CBC/PKCS7Padding with C, In all the Github, I can't find any repo

    Thanks you again

  5. BruceWind commented on Aug 29, 2019

    @BruceWind
    Owner

    you are welcome!
    Im busy this week, i hava a lot of work.Maybe you can to use the repo, and add some algorithms.
    write some code to test, then build a so file, and push to device.

    Then you can add you code to this repo,build with jni.

  6. BruceWind commented on Aug 29, 2019

    @BruceWind
    Owner

    There is a great article, C++使用AES+Base64算法对文本进行加密,but the algoritm is AES128,isnt 256。

  7. VincentChen1212 commented on Aug 30, 2019

    @VincentChen1212
    Author

    Hi,

    Thanks for your helping.
    My Business Model is using AES256/CBC/PKCS7Padding,
    And I must use kotlin-native platform to build my project,
    it only support c (don't support c++),
    so I am so sad to find no suitable project (I don't understand c/c++ )

    Thanks You VERY VERY VERY Much

  8. BruceWind commented on Aug 30, 2019

    @BruceWind
    Owner

    I think, no kotlin-native in Android. Only "Java call native" in Android. Java can call native interface,regardless C , C++ or Assembly language.
    Do you know I mean?

  9. BruceWind commented on Aug 30, 2019

    @BruceWind
    Owner

    I mean you can use extern "C" to call you C++ code. like this calling-c-dll-from-java.

  10. VincentChen1212 commented on Sep 2, 2019

    @VincentChen1212
    Author

    Hi,

    Thanks for your helping.
    My present situation : already create base64/sha/hmac using cinterop in kotlin-native project, now aes256 dosen't implement, but no suitable AES256/CBC/PKCS7Padding using c to reference.

    Thanks You very much

  11. BruceWind commented on Sep 2, 2019

    @BruceWind
    Owner

    okay,
    this week, i dont have a lot of work, maybe the repo will go ahead a little.

  12. VincentChen1212 commented on Sep 3, 2019

    @VincentChen1212
    Author

    Hi,
    It's a Good news for me.
    Thanks for your helping.

    My Test Data is:
    val data = "Discover interesting projects and people to populate your personal news feed"
    val key = "XENT95ZAYCPH2CLFT7M2Y3WEWKB846B8"
    val iv = "B3LCLM7CMXLY3ZAF"
    
    The resule is:
    JapXrfLPtd5bAkc69VtkeNlUeE/pgYdszgSQoqrDZEmg3GkA6wYx9+JaAtzNRg2ConKHmHtG/gCtNwpyO62OO+Jj+HnsxQwtvm8qkP2hpRI=
    

    You are really my HERO

    Thanks you very much

  13. BruceWind commented on Sep 3, 2019

    @BruceWind
    Owner

    I think, maybe you are finding a wrong direction.

    Java only provides PKCS#5 padding, but it is the same as PKCS#7 padding. See this question on Crypto.SE:

    What is the difference between PKCS#5 padding and PKCS#7 padding

    They are interchangeable for the common block ciphers like AES and DES.
    And such as AES&DES algorithm in cnblogs.

    Then, I wrote a class to test.

    import android.util.Base64;
    
    import java.security.spec.AlgorithmParameterSpec;
    
    import javax.crypto.Cipher;
    import javax.crypto.spec.IvParameterSpec;
    import javax.crypto.spec.SecretKeySpec;
    
    public class AESTest
    {
    
        private static String KEY_AES = "D(G+KbPeShVmYq3t";
        public static String encrypt7(String value) {
            try {
                byte[] key = KEY_AES.getBytes("UTF-8");
                byte[] ivs = KEY_AES.getBytes("UTF-8");
                Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
                SecretKeySpec secretKeySpec = new SecretKeySpec(key, "AES");
                AlgorithmParameterSpec paramSpec = new IvParameterSpec(ivs);
                cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, paramSpec);
                return Base64.encodeToString(cipher.doFinal(value.getBytes("UTF-8")), Base64.DEFAULT);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
    
        public static String encrypt5(String value) {
            try {
                byte[] key = KEY_AES.getBytes("UTF-8");
                byte[] ivs = KEY_AES.getBytes("UTF-8");
                Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
                SecretKeySpec secretKeySpec = new SecretKeySpec(key, "AES");
                AlgorithmParameterSpec paramSpec = new IvParameterSpec(ivs);
                cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, paramSpec);
                return Base64.encodeToString(cipher.doFinal(value.getBytes("UTF-8")), Base64.DEFAULT);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
    }
    

    The result of two function is equal.

    Look this: struct padding in crypto++ doc. I think, Crypto++ doesn't support PKCS7Padding.

  14. changed the title [-] Support AES256/CBC/PKCS7Padding ?[/-] [+]Could you please support AES256/CBC/PKCS7Padding?[/+] on Sep 3, 2019
  15. VincentChen1212 commented on Sep 3, 2019

    @VincentChen1212
    Author

    Hi,
    Thanks for your helping.
    I don't understand about C language, so if c only support pkcs5, it is ok.

    My test data is use java & C#, my coworker seem also use pkcs5 by java.

    You are truly my savior.
    I Really need C Code.

    Thanks for your helping.

  16. VincentChen1212 commented on Sep 4, 2019

    @VincentChen1212
    Author
  17. BruceWind commented on Sep 5, 2019

    @BruceWind
    Owner

    Obviously,length of Discover interesting projects an is 32, 32 same to 16 * 2.
    Perhaps, "length" and some loop have mistakes.

    If you ask about your aes algorithm, this isn't a question and answer platform.Pls go to Stackoverflow. Im Sorry.

  18. BruceWind commented on Feb 24, 2021

    @BruceWind
    Owner

    sorry, AES no longer support,
    I have pushed code that use chacah20 instead of AES. #40

  19. PeterleSoftwares commented on Aug 9, 2021

    @PeterleSoftwares

    There is a great article, C++使用AES+Base64算法对文本进行加密,but the algoritm is AES128,isnt 256。

    Thanks to mr. BruceWind!!! He saved my life with this article referral!!!

  20. BruceWind commented on Aug 10, 2021

    @BruceWind
    Owner

    @PeterleSoftwares
    You are welcome. Very appreciate that it helped you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions