public static String encryptECB(final byte[] concatenatedHashValue,final Long turnoverCounter,final SecretKey symmetricKey,int turnOverCounterLengthInBytes) throws NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
  final ByteBuffer byteBufferIV=ByteBuffer.allocate(16);
  byteBufferIV.put(concatenatedHashValue);
  final byte[] IV=byteBufferIV.array();
  final ByteBuffer byteBufferData=ByteBuffer.allocate(16);
  byteBufferData.putLong(turnoverCounter);
  final byte[] data=byteBufferData.array();
  byte[] turnOverCounterByteRep=get2ComplementRepForLong(turnoverCounter,turnOverCounterLengthInBytes);
  System.arraycopy(turnOverCounterByteRep,0,data,0,turnOverCounterByteRep.length);
  final Cipher cipher=Cipher.getInstance("AES/ECB/NoPadding","BC");
  cipher.init(Cipher.ENCRYPT_MODE,symmetricKey);
  final byte[] intermediateResult=cipher.doFinal(IV);
  final byte[] result=new byte[data.length];
  for (int i=0; i < data.length; i++) {
    result[i]=(byte)((data[i]) ^ (intermediateResult[i]));
  }
  final byte[] encryptedTurnOverValue=new byte[turnOverCounterLengthInBytes];
  System.arraycopy(result,0,encryptedTurnOverValue,0,turnOverCounterLengthInBytes);
  return CashBoxUtils.base64Encode(encryptedTurnOverValue,false);
}

public static String encryptECB ( final byte [ ] concatenatedHashValue , final Long turnoverCounter , final SecretKey symmetricKey , int turnOverCounterLengthInBytes ) throws NoSuchAlgorithmException , NoSuchProviderException , NoSuchPaddingException , InvalidKeyException , IllegalBlockSizeException , BadPaddingException { final ByteBuffer byteBufferIV = ByteBuffer . allocate ( 16 ) ; byteBufferIV . put ( concatenatedHashValue ) ; final byte [ ] IV = byteBufferIV . array ( ) ; final ByteBuffer byteBufferData = ByteBuffer . allocate ( 16 ) ; byteBufferData . putLong ( turnoverCounter ) ; final byte [ ] data = byteBufferData . array ( ) ; byte [ ] turnOverCounterByteRep = get2ComplementRepForLong ( turnoverCounter , turnOverCounterLengthInBytes ) ; System . arraycopy ( turnOverCounterByteRep , 0 , data , 0 , turnOverCounterByteRep . length ) ; final Cipher cipher = Cipher . getInstance ( "AES/ECB/NoPadding" , "BC" ) ; cipher . init ( Cipher . ENCRYPT_MODE , symmetricKey ) ; final byte [ ] intermediateResult = cipher . doFinal ( IV ) ; final byte [ ] result = new byte [ data . length ] ; for ( int i = 0 ; i < data . length ; i ++ ) { result [ i ] = ( byte ) ( ( data [ i ] ) ^ ( intermediateResult [ i ] ) ) ; } final byte [ ] encryptedTurnOverValue = new byte [ turnOverCounterLengthInBytes ] ; System . arraycopy ( result , 0 , encryptedTurnOverValue , 0 , turnOverCounterLengthInBytes ) ; return CashBoxUtils . base64Encode ( encryptedTurnOverValue , false ) ; }
method for aes encryption in ecb mode
