![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e460. Getting the Bytes of a Generated Symmetric Keytry { // 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 } catch (NoSuchAlgorithmException e) { }
e459. Generating a Symmetric Key
© 2002 Addison-Wesley. |