Search in sources :

Example 1 with ISO7816d4Padding

use of org.spongycastle.crypto.paddings.ISO7816d4Padding in project jmulticard by ctt-gob-es.

the class AmAESCrypto method initCiphers.

private void initCiphers(final byte[] key, final byte[] iv) {
    // get the keyBytes
    this.keyBytes = new byte[key.length];
    System.arraycopy(key, 0, this.keyBytes, 0, key.length);
    this.keyP = new KeyParameter(this.keyBytes);
    // get the IV
    this.IV = new byte[BLOCK_SIZE];
    System.arraycopy(iv, 0, this.IV, 0, this.IV.length);
    // create the ciphers
    // AES block cipher in CBC mode with ISO7816d4 padding
    this.encryptCipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESEngine()), new ISO7816d4Padding());
    this.decryptCipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESEngine()), new ISO7816d4Padding());
    // create the IV parameter
    final ParametersWithIV parameterIV = new ParametersWithIV(this.keyP, this.IV);
    this.encryptCipher.init(true, parameterIV);
    this.decryptCipher.init(false, parameterIV);
}
Also used : ParametersWithIV(org.spongycastle.crypto.params.ParametersWithIV) PaddedBufferedBlockCipher(org.spongycastle.crypto.paddings.PaddedBufferedBlockCipher) AESEngine(org.spongycastle.crypto.engines.AESEngine) ISO7816d4Padding(org.spongycastle.crypto.paddings.ISO7816d4Padding) KeyParameter(org.spongycastle.crypto.params.KeyParameter) CBCBlockCipher(org.spongycastle.crypto.modes.CBCBlockCipher)

Example 2 with ISO7816d4Padding

use of org.spongycastle.crypto.paddings.ISO7816d4Padding in project jmulticard by ctt-gob-es.

the class AmCryptoProvider method addPadding.

/**
 * Diese Methode fullt ein Byte-Array mit dem Wert 0x80 und mehreren 0x00
 * bis die Lange des abergebenen Byte-Array ein Vielfaches der Blocklange
 * ist. Dies ist die ISO9797-1 Padding-Methode 2 bzw. ISO7816d4-Padding
 * @param data Das Byte-Array welches aufgefallt werden soll.
 * @return Das gefallte Byte-Array.
 */
public final byte[] addPadding(final byte[] data) {
    final int len = data.length;
    final int nLen = (len / getBlockSize() + 1) * getBlockSize();
    final byte[] n = new byte[nLen];
    System.arraycopy(data, 0, n, 0, data.length);
    new ISO7816d4Padding().addPadding(n, len);
    return n;
}
Also used : ISO7816d4Padding(org.spongycastle.crypto.paddings.ISO7816d4Padding)

Aggregations

ISO7816d4Padding (org.spongycastle.crypto.paddings.ISO7816d4Padding)2 AESEngine (org.spongycastle.crypto.engines.AESEngine)1 CBCBlockCipher (org.spongycastle.crypto.modes.CBCBlockCipher)1 PaddedBufferedBlockCipher (org.spongycastle.crypto.paddings.PaddedBufferedBlockCipher)1 KeyParameter (org.spongycastle.crypto.params.KeyParameter)1 ParametersWithIV (org.spongycastle.crypto.params.ParametersWithIV)1