Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
VincentChen1212 opened this issue Aug 28, 2019 · 18 comments
Open

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

VincentChen1212 opened this issue Aug 28, 2019 · 18 comments

Comments

@VincentChen1212
Copy link

HI

This is a good Project.

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

Thanks

@VincentChen1212 VincentChen1212 changed the title Support AES256/CBC/PKCS7Padding ??? Support AES256/CBC/PKCS7Padding ? Aug 28, 2019
@BruceWind
Copy link
Owner

BruceWind commented Aug 28, 2019

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

@BruceWind
Copy link
Owner

BruceWind commented Aug 28, 2019

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

some algoritms will soon.

@VincentChen1212
Copy link
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

@BruceWind
Copy link
Owner

BruceWind commented Aug 29, 2019

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.

@BruceWind
Copy link
Owner

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

@VincentChen1212
Copy link
Author

VincentChen1212 commented Aug 30, 2019

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

@BruceWind
Copy link
Owner

BruceWind commented Aug 30, 2019

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?

@BruceWind
Copy link
Owner

BruceWind commented Aug 30, 2019

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

@VincentChen1212
Copy link
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

@BruceWind
Copy link
Owner

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

@VincentChen1212
Copy link
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

@BruceWind
Copy link
Owner

BruceWind commented Sep 3, 2019

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.

@BruceWind BruceWind changed the title Support AES256/CBC/PKCS7Padding ? Could you please support AES256/CBC/PKCS7Padding? Sep 3, 2019
@VincentChen1212
Copy link
Author

VincentChen1212 commented Sep 3, 2019

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.

@VincentChen1212

This comment has been minimized.

@BruceWind
Copy link
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.

@BruceWind
Copy link
Owner

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

@PeterleSoftwares
Copy link

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!!!

@BruceWind
Copy link
Owner

BruceWind commented Aug 10, 2021

@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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants