手动删除由RSA / ECB / OAEPWITHSHA-256ANDMGF1PADDING添加的填充

时间:2016-05-27 10:46:09

标签: java encryption rsa padding

我正在使用带有SunJCE的PKCS11来解密字节数据。使用与PKCS11不兼容的RSA / ECB / OAEPWITHSHA-256ANDMGF1PADDING对数据进行加密。所以我将不得不手动删除它,但直到现在都没有运气。以下是我尝试删除它RSA_KEY_SIZE是2048:

if (paddedPlainText.length < RSA_KEY_SIZE / 8) {
   byte[] tmp = new byte[RSA_KEY_SIZE / 8];
   System.arraycopy(paddedPlainText, 0, tmp, tmp.length - paddedPlainText.length, paddedPlainText.length);
   System.out.println("Zero padding to " + (RSA_KEY_SIZE / 8));
   paddedPlainText = tmp;
}

OAEPParameterSpec paramSpec = new OAEPParameterSpec("SHA-256", "MGF1", MGF1ParameterSpec.SHA256, pSrc);
RSAPadding padding = RSAPadding.getInstance(RSAPadding.PAD_OAEP_MGF1, RSA_KEY_SIZE / 8, new SecureRandom(), paramSpec);
byte[] plainText = padding.unpad(paddedPlainText);

0 个答案:

没有答案