Generating a Symmetric Key : Key Generator « Security « Java Tutorial






import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;

public class Main {
  public static void main(String[] argv) throws Exception {
    // Generate a DES key
    KeyGenerator keyGen = KeyGenerator.getInstance("DES");
    SecretKey key = keyGen.generateKey();

    // Generate a Blowfish key
    keyGen = KeyGenerator.getInstance("Blowfish");
    key = keyGen.generateKey();

    // Generate a triple DES key
    keyGen = KeyGenerator.getInstance("DESede");
    key = keyGen.generateKey();
  }
}








36.21.Key Generator
36.21.1.Key Generator Demo
36.21.2.Generating a Symmetric Key
36.21.3.Getting the Bytes of a Generated Symmetric Key
36.21.4.Generate a key for the HMAC-SHA1 keyed-hashing algorithm
36.21.5.Encryption and Decryption using Symmetric Keys
36.21.6.Get the bytes of the public and private keys
36.21.7.Get the formats of the encoded bytes