Java SecretKeySpec create 64 bit key

Description

Java SecretKeySpec create 64 bit key



import java.security.GeneralSecurityException;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

public class Main {
  public static void main(String[] args) {
    byte[] data = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };

    SecretKeySpec key64 = new SecretKeySpec(new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }, "Blowfish");

    try {/*from ww  w .  j a v a2s . c o  m*/
      Cipher c = Cipher.getInstance("Blowfish/ECB/NoPadding");

      c.init(Cipher.ENCRYPT_MODE, key64);

      c.doFinal(data);

      System.out.println("64 bit test: passed");
    } catch (SecurityException e) {
      e.printStackTrace();
    } catch (GeneralSecurityException e) {
      e.printStackTrace();
    }

  }
}



PreviousNext

Related