Example usage for javax.crypto ShortBufferException ShortBufferException

List of usage examples for javax.crypto ShortBufferException ShortBufferException

Introduction

In this page you can find the example usage for javax.crypto ShortBufferException ShortBufferException.

Prototype

public ShortBufferException(String msg) 

Source Link

Document

Constructs a ShortBufferException with the specified detail message.

Usage

From source file:org.opensc.pkcs11.spi.PKCS11CipherSpi.java

@Override
protected int engineUpdate(byte[] input, int off, int len, byte[] output, int output_off)
        throws ShortBufferException {
    try {//from  w  ww  . j  a v a 2s.  c o m
        this.count += len;

        if (this.mode == Cipher.DECRYPT_MODE)
            return updateDecryptNativeOff(this.worker.getPvh(), this.worker.getSlotHandle(),
                    this.worker.getSessionHandle(), this.worker.getHandle(), input, off, len, output,
                    output_off);
        else
            return updateEncryptNativeOff(this.worker.getPvh(), this.worker.getSlotHandle(),
                    this.worker.getSessionHandle(), this.worker.getHandle(), input, off, len, output,
                    output_off);

    } catch (PKCS11Exception e) {
        log.error("PKCS11Exception caught:", e);
        throw new ShortBufferException("PKCS11 exception:" + e);
    }
}

From source file:org.opensc.pkcs11.spi.PKCS11CipherSpi.java

@Override
protected int engineDoFinal(byte[] input, int off, int len, byte[] output, int output_off)
        throws ShortBufferException, IllegalBlockSizeException, BadPaddingException {
    int ret;//from   w  ww.  j ava2s. c  o m

    try {
        if (this.mode == Cipher.DECRYPT_MODE)
            if (this.count == 0)
                ret = doDecryptNativeOff(this.worker.getPvh(), this.worker.getSlotHandle(),
                        this.worker.getSessionHandle(), this.worker.getHandle(), input, off, len, output,
                        output_off);
            else
                ret = doFinalDecryptNativeOff(this.worker.getPvh(), this.worker.getSlotHandle(),
                        this.worker.getSessionHandle(), this.worker.getHandle(), input, off, len, output,
                        output_off);
        else if (this.count == 0)
            ret = doEncryptNativeOff(this.worker.getPvh(), this.worker.getSlotHandle(),
                    this.worker.getSessionHandle(), this.worker.getHandle(), input, off, len, output,
                    output_off);
        else
            ret = doFinalEncryptNativeOff(this.worker.getPvh(), this.worker.getSlotHandle(),
                    this.worker.getSessionHandle(), this.worker.getHandle(), input, off, len, output,
                    output_off);

    } catch (PKCS11Exception e) {
        log.error("PKCS11Exception caught:", e);
        throw new ShortBufferException("PKCS11 exception:" + e);
    }

    this.count = 0;
    return ret;
}

From source file:org.talend.mdm.commmon.util.core.Crypt.java

public static Crypt getDESCryptInstance(String sharedSecret) throws ShortBufferException {
    byte[] key = new byte[8];
    byte[] bytes;
    try {/*from  ww w  .ja  v  a 2  s  .  c  o m*/
        bytes = sharedSecret.getBytes("utf-8");
    } catch (UnsupportedEncodingException uee) {
        throw new ShortBufferException("The shared secret cannot be used as a key");
    }
    if (bytes.length < 8)
        throw new ShortBufferException("The shared secret is too short");
    System.arraycopy(bytes, 0, key, 0, 8);
    return new Crypt(key, "DES");
}