简体   繁体   English

java.io.IOException:异常解包私钥 - java.security.InvalidKeyException:pad 块损坏

[英]java.io.IOException: exception unwrapping private key - java.security.InvalidKeyException: pad block corrupted

I am trying to connect an android app to an XML web service under IIS over SSL (Self Signed SSL).我正在尝试通过 SSL(自签名 SSL)将一个 android 应用程序连接到 IIS 下的 XML Web 服务。 I've followed below procedure:我遵循了以下程序:

  1. creating a Self Signed Certificate under IIS Manager在 IIS 管理器下创建自签名证书
  2. export that certificate as a pfx file将该证书导出为 pfx 文件
  3. then converting pfx to (java keystore) jks (PKCS12 format) as detailed below然后将 pfx 转换为(java 密钥库)jks(PKCS12 格式),如下详述
  4. embedding jks as a raw data in android app将 jks 作为原始数据嵌入到 android 应用程序中
  5. and reading the content of jks file as follows并读取 jks 文件的内容如下

Converting pfx to jks将 pfx 转换为 jks

keytool -importkeystore -srckeystore cert.pfx -srcstoretype pkcs12 
-destkeystore cert.jks -deststoretype pkcs12

Reading the content of jks阅读jks的内容

KeyStore keyStore = KeyStore.getInstance("pkcs12");
InputStream in = _context.getResources().openRawResource(R.raw.cert);
try
{
    keyStore.load(in, "123456".toCharArray());
    mgrFact.init(keyStore, "123456".toCharArray());
}
catch (Throwable t)
{
    logger.error(t.getMessage());
}
finally
{
    in.close();
}

And now keyStore.load throws the following exception现在keyStore.load抛出以下异常

java.io.IOException: exception unwrapping private key 
-java.security.InvalidKeyException: pad block corrupted

Where may I've made a mistake?我可能在哪里犯了错误?

In fact, I followed what has been described here事实上,我遵循了这里描述的内容

Thanks谢谢

I know that the question is 4 years old, but just in case someone else get the same error:我知道这个问题已经有 4 年了,但以防万一其他人遇到同样的错误:

I don't know why but there seem to be differences between the keystore generated with keytool of OpenJDK 11 and the one (with same certificates / keys / passwords) generated by keytool of Oracle JDK 8.我不知道为什么,但 OpenJDK 11 的 keytool 生成的密钥库与 Oracle JDK 8 的 keytool 生成的密钥库(具有相同的证书/密钥/密码)之间似乎存在差异。

The problem for me arose using the keystore-jdk11.p12 under我的问题是使用下的keystore-jdk11.p12

  • Tomcat 8.5雄猫 8.5
  • Oracle JVM 8 (u241) Oracle JVM 8 (u241)

I fixed this simply reimporting the content of the keystore generated with OpenJDK 11 with keytool of Oracle JDK 8, with我修复了这个问题,只需使用 Oracle JDK 8 的 keytool 重新导入 OpenJDK 11 生成的密钥库的内容,

/path/of/jdk8.241/bin/keytool \
   -importkeystore \
   -srckeystore keystore-jdk11.p12 \
   -destkeystore keystore-jdk8.p12 \
   -deststoretype pkcs12

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java 11 - 椭圆曲线私钥 - java.security.InvalidKeyException:IOException:DER 输入,Integer 标签错误 - Java 11 - elliptic curve private key - java.security.InvalidKeyException: IOException : DER input, Integer tag error JAVA中的加密私钥:java.security.InvalidKeyException - Encrypted Private key in JAVA: java.security.InvalidKeyException java.security.InvalidKeyException - java.security.InvalidKeyException JAVA 11 - 椭圆曲线私钥 - 原因:java.security.InvalidKeyException:IOException:版本不匹配:(支持:00,解析:01 - JAVA 11 - elliptic curve private key - Caused by: java.security.InvalidKeyException: IOException : version mismatch: (supported: 00, parsed: 01 java.security.InvalidKeyException:密钥大小错误 - java.security.InvalidKeyException: Wrong key size InvalidKeyException java.security.InvalidKeyException:没有安装的提供程序支持此键:(null) - InvalidKeyException java.security.InvalidKeyException: No installed provider supports this key: (null) java.security.InvalidKeyException:从PEM文件生成公钥,私钥时无效的密钥格式 - java.security.InvalidKeyException: invalid key format while generating public, private key from PEM file 初始化密码时,Java密码抛出异常:java.security.InvalidKeyException:密钥大小非法 - Java Cryptography throwing Exception while initializing Cipher: java.security.InvalidKeyException: Illegal key size 获取异常java.security.InvalidKeyException:无效的AES密钥长度:444字节 - Getting Exception java.security.InvalidKeyException: Invalid AES key length: 444 bytes BouncyCastle 签名:java.security.InvalidKeyException:密钥格式无效 - BouncyCastle Signing: java.security.InvalidKeyException: invalid key format
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM