V
vaneric
I am a beginner to JCE. I have been trying out some tutorials on the
topic of encryption using the Cipher class.
I wrote the following code,
byte[] initvector=new byte[]{ 0x00, 0x00, 0x00, 0x01, 0x04, 0x05,
0x06, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding", "BC");
KeyGenerator kgen = KeyGenerator.getInstance("AES", "BC");
generator.init(192);
Key encKey = kgen.generateKey();
cipher.init(Cipher.ENCRYPT_MODE, encKey,
new IvParameterSpec(initvector));
Why do I have to create a decryption key like
Key decKey = new SecretKeySpec(
encKey.getEncoded(), encKey.getAlgorithm());
Can't I use the encKey itself to do the decoding? Cipher only expects
an object implementing Key interface as the second argument.Why do I
have to create a SecretKeySpec object?
Any help most welcome.
Thanks in advance,
eric
topic of encryption using the Cipher class.
I wrote the following code,
byte[] initvector=new byte[]{ 0x00, 0x00, 0x00, 0x01, 0x04, 0x05,
0x06, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding", "BC");
KeyGenerator kgen = KeyGenerator.getInstance("AES", "BC");
generator.init(192);
Key encKey = kgen.generateKey();
cipher.init(Cipher.ENCRYPT_MODE, encKey,
new IvParameterSpec(initvector));
Why do I have to create a decryption key like
Key decKey = new SecretKeySpec(
encKey.getEncoded(), encKey.getAlgorithm());
Can't I use the encKey itself to do the decoding? Cipher only expects
an object implementing Key interface as the second argument.Why do I
have to create a SecretKeySpec object?
Any help most welcome.
Thanks in advance,
eric