验证在JavaCard上签名的数据时出现Java BadPaddingException [英] Java BadPaddingException when verifying data signed on a JavaCard

查看:69
本文介绍了验证在JavaCard上签名的数据时出现Java BadPaddingException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用密码对JavaCard上的某些数据进行签名,然后将其输出到文本文件中,再将其读入Java程序并尝试进行验证.我不断收到BadPaddingException.

I'm signing some data on a JavaCard with a cipher, then outputting it into a text file, reading it into a java program and trying to verify it. I keep getting a BadPaddingException.

我正在JavaCard小程序上这样签名:

I'm signing it like so on my JavaCard applet:

Cipher cipher = Cipher.getInstance(Cipher.ALG_RSA_PKCS1, false);
cipher.init(key.getPrivate(), Cipher.MODE_ENCRYPT);
short sigCipherLength = cipher.doFinal(inputArray, inputOffset, inputLength, outputArray, outputOffset);

并以此验证它(在我的Java程序上):

And verifying it like this (on my Java program):

Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(Cipher.DECRYPT_MODE, publicKey);
byte[] decryptedText = cipher.doFinal(inputArray);

当将Cipher.getInstance与"RSA"一起使用时,解除对RSA/ECB/RKPCS1Padding的限制吗?我一直在努力摆脱错误.

When using Cipher.getInstance with "RSA" it defautls to RSA/ECB/RKPCS1Padding does it not? I'm stuck on how to get rid of the error.

为清楚起见,更改加密和解密以签名和验证

to change encryption and decyrption to sign and verify, for clarity

推荐答案

这可能会有所帮助:

Maybe this will help: Which padding is used by javax.crypto.Cipher for RSA. In short, do not rely on the default, it is best to fully qualify the cipher.

这篇关于验证在JavaCard上签名的数据时出现Java BadPaddingException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆