我正在使用带有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);