I have a simple Xades / BES implementation and two situations.
On windows 7 32bit with java
java version "1.7.0_25" Java(TM) SE Runtime Environment (build 1.7.0_25-b17) Java HotSpot(TM) Client VM (build 23.25-b01, mixed mode)
Windows Server 2008 Server has 64 bits and the same JVM.
My application works fine on 32-bit Windows 7, however, when I try to run the compiled code on Windows 2008 Server, I get an error message:
javax.crypto.BadPaddingException: Data must start with zero at sun.security.rsa.RSAPadding.unpadV15(Unknown Source) at sun.security.rsa.RSAPadding.unpad(Unknown Source) at com.sun.crypto.provider.RSACipher.doFinal(RSACipher.java:349) at com.sun.crypto.provider.RSACipher.engineDoFinal(RSACipher.java:382) at javax.crypto.Cipher.doFinal(Cipher.java:2087)
The problem code field is as follows:
public static byte[] getDecryptedSignatureValue(XMLSignature signature) throws XadesElementException, InvalidKeyException { byte[] signatureValue = null; try { KeyInfo keyInfo = signature.getKeyInfo(); PublicKey key = keyInfo.getPublicKey(); Cipher cipher = getCipher("RSA/ECB/PKCS1Padding"); cipher.init(Cipher.DECRYPT_MODE, key); signatureValue = signature.getSignatureValue(); byte[] cipherData = cipher.doFinal(signatureValue); return cipherData; } catch (KeyResolverException | XMLSignatureException | IllegalBlockSizeException | BadPaddingException ex) { Logger.getLogger(KeyUtils.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(KeyUtils.class.getName()).log(Level.SEVERE, null, "SignatureValue:"+ BaseUtils.toBase64String(signatureValue)); } finally { } return null; }
The only thing I can think of is the difference in architecture. Am I missing something? What could be the problem?
Thanks in advance.
EDIT: Here are my new discoveries. 1. I tested my application on the 64-bit version of Windows 7, and there were no problems signing and checking. 2. More interestingly, I tested the application on another 64-bit Windows Server 2008 and worked successfully.
I think there is a configuration setting for something, but I could not understand that.
source share