예제 #1
0
 private byte[] doFinal() throws BadPaddingException, IllegalBlockSizeException {
   byte[] t = new byte[2048];
   int n = implDoFinal(t, 0, t.length);
   byte[] out = new byte[n];
   System.arraycopy(t, 0, out, 0, n);
   return out;
 }
예제 #2
0
 // see JCE spec
 protected byte[] engineDoFinal(byte[] in, int inOfs, int inLen)
     throws IllegalBlockSizeException, BadPaddingException {
   implUpdate(in, inOfs, inLen);
   int n = implDoFinal(buffer, 0, buffer.length);
   byte[] out = new byte[n];
   System.arraycopy(buffer, 0, out, 0, n);
   return out;
 }
예제 #3
0
 private int implDoFinal(byte[] out, int outOfs, int outLen)
     throws BadPaddingException, IllegalBlockSizeException {
   if (bufOfs > maxInputSize) {
     throw new IllegalBlockSizeException(
         "Data must not be longer " + "than " + maxInputSize + " bytes");
   }
   try {
     ensureInitialized();
     PKCS11 p11 = token.p11;
     int n;
     switch (mode) {
       case MODE_ENCRYPT:
         n = p11.C_Encrypt(session.id(), buffer, 0, bufOfs, out, outOfs, outLen);
         break;
       case MODE_DECRYPT:
         n = p11.C_Decrypt(session.id(), buffer, 0, bufOfs, out, outOfs, outLen);
         break;
       case MODE_SIGN:
         byte[] tmpBuffer = new byte[bufOfs];
         System.arraycopy(buffer, 0, tmpBuffer, 0, bufOfs);
         tmpBuffer = p11.C_Sign(session.id(), tmpBuffer);
         if (tmpBuffer.length > outLen) {
           throw new BadPaddingException("Output buffer too small");
         }
         System.arraycopy(tmpBuffer, 0, out, outOfs, tmpBuffer.length);
         n = tmpBuffer.length;
         break;
       case MODE_VERIFY:
         n = p11.C_VerifyRecover(session.id(), buffer, 0, bufOfs, out, outOfs, outLen);
         break;
       default:
         throw new ProviderException("internal error");
     }
     return n;
   } catch (PKCS11Exception e) {
     throw (BadPaddingException) new BadPaddingException("doFinal() failed").initCause(e);
   } finally {
     initialized = false;
     session = token.releaseSession(session);
   }
 }
예제 #4
0
 private void implUpdate(byte[] in, int inOfs, int inLen) {
   try {
     ensureInitialized();
   } catch (PKCS11Exception e) {
     throw new ProviderException("update() failed", e);
   }
   if ((inLen == 0) || (in == null)) {
     return;
   }
   if (bufOfs + inLen > maxInputSize) {
     bufOfs = maxInputSize + 1;
     return;
   }
   System.arraycopy(in, inOfs, buffer, bufOfs, inLen);
   bufOfs += inLen;
 }