Source Code : Getting the Bytes of a Generated Symmetric Key
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Getting the Bytes of a Generated Symmetric Key
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
public class Main {
public static void main(String[] argv) throws Exception {
// Generate a key
KeyGenerator keyGen = KeyGenerator.getInstance("DESede");
SecretKey key = keyGen.generateKey();
// Get the bytes of the key
byte[] keyBytes = key.getEncoded();
int numBytes = keyBytes.length;
// The bytes can be converted back to a SecretKey
SecretKey key2 = new SecretKeySpec(keyBytes, "DESede");
boolean b = key.equals(key2); // true
}
}
Thank with us