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);
}
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;
}
Aggregations