Why the first call of of encryption take hundred time of the second one
byte[] key = //... secret sequence of bytes
byte[] dataToSend = ...
Here's my encryption method:
public static byte[] enc(byte data[], byte key[]
{
Cipher c = Cipher.getInstance("AES");
SecretKeySpec k =
new SecretKeySpec(key, "AES");
c.init(Cipher.ENCRYPT_MODE, k);
byte[] encryptedData = c.doFinal(dataToSend);
return encryptedData;
}
and here is the test code
byte [] key="1111111111111111".toByteArray();
byte [] data=new byte [32];
for(int i=0;i<1000;i++)
{
long x=System.nanoTime();
enc(data,key);
System.out.println(System.nanoTime()-x);
}
The first value will be something like 20300, then the other value will drop to 50 , 35 , 42 ..etc If its something that need loading can i do this before starting the application . I am working in network protocol and need to do benchmark with another one.