<html><body><div style="color:#000; background-color:#fff; font-family:Courier New, courier, monaco, monospace, sans-serif;font-size:10px"><div dir="ltr" id="yui_3_16_0_1_1417757454301_8685">Hi all</div><div id="yui_3_16_0_1_1417757454301_8745" dir="ltr"><br></div><div id="yui_3_16_0_1_1417757454301_8744" dir="ltr">I'm getting this error:</div><div id="yui_3_16_0_1_1417757454301_9935" dir="ltr"><br></div><div id="yui_3_16_0_1_1417757454301_8746" dir="ltr">Caused by: java.security.ProviderException: update() failed<br style="" class="">        at sun.security.pkcs11.P11Cipher.implUpdate(P11Cipher.java:565)<br style="" class="">        at sun.security.pkcs11.P11Cipher.engineUpdate(P11Cipher.java:464)<br style="" class="">        at sun.security.pkcs11.P11Cipher.engineUpdate(P11Cipher.java:452)<br style="" class="">        at javax.crypto.Cipher.update(DashoA13*..)<br style="" class="">        at javax.crypto.CipherOutputStream.write(DashoA13*..)<br style="" class="">        at javax.crypto.CipherOutputStream.write(DashoA13*..)<br style="" class="">        ... 42 more<br style="" class="">Caused by: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_DATA_LEN_RANGE<br style="" class="">        at sun.security.pkcs11.wrapper.PKCS11.C_EncryptUpdate(Native Method)<br style="" class="">        at sun.security.pkcs11.P11Cipher.implUpdate(P11Cipher.java:517)<br style="" class="">        ... 51 more<br style="" class=""></div><div id="yui_3_16_0_1_1417757454301_8816" dir="ltr"><br></div><div style="" class="" id="yui_3_16_0_1_1417757454301_8746" dir="ltr">trying to use softhsm-2.0.0b1 with SunPKCS11 (java 1.6.45).  The same code works fine with a regular java key store.  I'm doing something like this:</div><div id="yui_3_16_0_1_1417757454301_9449" style="" class="" dir="ltr"><br></div><div id="yui_3_16_0_1_1417757454301_9286" style="" class="" dir="ltr">    public void start() {<br style="" class="">        try {<br style="" class="">            Provider p = new SunPKCS11(configFile);<br style="" class="">            <br style="" class="">            if (-1 == Security.addProvider(p)) {<br style="" class="">                throw new RuntimeException("could not add security provider " + p.getName());<br style="" class="">            }<br style="" class="">            <br style="" class="">            KeyStore keystore = KeyStore.getInstance("PKCS11", p);<br style="" class="">            keystore.load(null, pin.toCharArray());<br style="" class="">            key = keystore.getKey(keyAlias, pin.toCharArray());<br style="" class="">        } catch (Exception e) {<br style="" class="">            e.printStackTrace();<br style="" class="">        }<br style="" class="">    }<br style="" class="">    <br style="" class="">    public InputStream getInputStream(File file) throws IOException {<br style="" class="">        try {<br style="" class="">            Cipher decryptCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");<br style="" class="">            decryptCipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv));<br style="" class="">            return new CipherInputStream(new FileInputStream(file), decryptCipher);<br style="" class="">        } catch (Exception e) {<br style="" class="">            throw new IOException(e);<br style="" class="">        }<br style="" class="">    }<br style="" class=""><br style="" class="">    public OutputStream getOutputStream(File file) throws IOException {<br style="" class="">        try {<br style="" class="">            Cipher encryptCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");<br style="" class="">            encryptCipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(iv));<br style="" class="">            return new CipherOutputStream(new FileOutputStream(file), encryptCipher);<br style="" class="">        } catch (Exception e) {<br style="" class="">            throw new IOException(e);<br style="" class="">        }<br style="" class="">    }<br style="" class=""></div><div style="" class="" id="yui_3_16_0_1_1417757454301_8746" dir="ltr"><br></div><div id="yui_3_16_0_1_1417757454301_9692" style="" class="" dir="ltr">Is this maybe a known limitation for softhsm2 ? there is some workaround ? Thx for your help.<br></div></div></body></html>