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

一、RSA Android加密的数据服务器上无法解密? #2

Open
quanqiuheike opened this issue Oct 19, 2017 · 1 comment
Open

Comments

@quanqiuheike
Copy link

quanqiuheike commented Oct 19, 2017

一、android加密的数据服务器上无法解密?

“算法/模式/填充”

  • android的rsa加密方式是--------RSA/ECB/NoPadding或者RSA/None/NoPadding
  • 标准jdk的rsa加密方式是-------- RSA/ECB/PKCS1Padding或者RSA/None/PKCS1Padding

加密时要设置标准jdk的加密方式

        /*加密方式,android的*/
        public static final String  mAlgorithm= "RSA/ECB/NoPadding";
        public static final String  mAlgorithm= "RSA/None/NoPadding";
          /*加密方式,标准jdk的*/
        public static final String  mAlgorithm= "RSA/ECB/PKCS1Padding";
        public static final String  mAlgorithm= "RSA/None/PKCS1Padding";

加解密数据 两种均可,亲测

    Cipher cp = Cipher.getInstance("RSA/ECB/PKCS1Padding");
    Cipher cp = Cipher.getInstance("RSA/None/PKCS1Padding");

所以能否配置为可配置的算法模式填充?

@quanqiuheike quanqiuheike changed the title # 一、android加密的数据服务器上无法解密? # 一、RSA Android加密的数据服务器上无法解密? Oct 19, 2017
@quanqiuheike quanqiuheike changed the title # 一、RSA Android加密的数据服务器上无法解密? 一、RSA Android加密的数据服务器上无法解密? Oct 19, 2017
@rabbitknight
Copy link

  1. 源码中,Base64加密使用Default模式,这导致编码后会出现“+”、“\r\n”等字符。
  2. 在HTTP传输的过程中,“+”等,可能会被忽略,这导致源签名/加密数据 和服务器实际收到的不一致,最终导致解密不出来。
  3. 建议使用Base64.URL_SAFE模式,将“+”等字符替换为"_-"。或者使用jutil包下java.util.Base64.getUrlEncoder()、getUrlDecoder替换源码中的Base64编码方案。

--- end ---

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

2 participants