Note that there are some explanatory texts on larger screens.

plurals
  1. POCan not verify signature value with certificate java
    text
    copied!<p>I have soap webservice. To validate messages we use signature with certificate.</p> <p>When I get message and validate it with client certificate it pass. Then I sign data by our private key certificate with this code</p> <pre><code>signature = Signature.getInstance("SHA1withRSA", "SunRsaSign"); byte[] dataToSign = someXMLNodeString.getBytes(); PrivateKey privateKey = SignatureUtil.getPrivateKeyForCertificate( "JKS", "keystorefile", "keystorepass".toCharArray(), "keydomain", "keydomainpass".toCharArray()); signatureValue = SignatureUtil.sign(dataToSign, signature, privateKey); public static PrivateKey getPrivateKeyForCertificate( String keyStoreAlgorithm, String keyStoreName, char[] keystorePass, String alias, char[] keyPassword) { KeyStore ks = null; try { ks = KeyStore.getInstance(keyStoreAlgorithm); } catch (KeyStoreException e) { e.printStackTrace(); return null; } FileInputStream ksfis = null; try { ksfis = new FileInputStream(keyStoreName); } catch (FileNotFoundException e) { e.printStackTrace(); return null; } BufferedInputStream ksbufin = new BufferedInputStream(ksfis); try { ks.load(ksbufin, keystorePass); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return null; } catch (CertificateException e) { e.printStackTrace(); return null; } catch (IOException e) { e.printStackTrace(); return null; } finally { if(null != ksbufin) { try { ksbufin.close(); } catch (IOException e) { e.printStackTrace(); } } } PrivateKey priv = null; try { priv = (PrivateKey) ks.getKey(alias, keyPassword); } catch (UnrecoverableKeyException e) { e.printStackTrace(); return null; } catch (KeyStoreException e) { e.printStackTrace(); return null; } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return null; } return priv; } public static byte[] sign(byte[] data, Signature signature, PrivateKey privateKey) throws InvalidKeyException, SignatureException { //Create a Signature object and initialize it with the private key signature.initSign(privateKey); // Update and sign the data signature.update(data); //Now that all the data to be signed has been read in, //generate a signature for it return signature.sign(); } </code></pre> <p>But when client validate my signature by my given certificate, it fails. I generated my certificate with these commands</p> <pre><code>keytool -genkey -alias keydomain -keysize 1024 -keyalg RSA -keystore keystorefile keytool -export -alias keydomain -sigalg SHA1withRSA -keystore .keystorefile -file keydomain.cer -rfc </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload