List of usage examples for javax.crypto.spec DESedeKeySpec DESedeKeySpec
public DESedeKeySpec(byte[] key) throws InvalidKeyException
key
as the key material for the DES-EDE key. From source file:Main.java
public static Key updGenerateKey(String key) { try {/*from w w w.j a va 2 s. com*/ DESedeKeySpec KeySpec = new DESedeKeySpec(UdpHexDecode(key)); SecretKeyFactory KeyFactory = SecretKeyFactory.getInstance("DESede"); Key k = ((KeyFactory.generateSecret(((KeySpec))))); return k; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static byte[] des3EncodeECB(byte[] key, byte[] data) throws Exception { Key deskey = null;/*ww w . j av a 2 s .co m*/ DESedeKeySpec spec = new DESedeKeySpec(key); SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("desede"); deskey = keyfactory.generateSecret(spec); Cipher cipher = Cipher.getInstance("desede" + "/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, deskey); byte[] bOut = cipher.doFinal(data); return bOut; }
From source file:Main.java
public static byte[] ees3DecodeECB(byte[] key, byte[] data) throws Exception { Key deskey = null;//from ww w. j av a2 s . c om DESedeKeySpec spec = new DESedeKeySpec(key); SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("desede"); deskey = keyfactory.generateSecret(spec); Cipher cipher = Cipher.getInstance("desede" + "/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, deskey); byte[] bOut = cipher.doFinal(data); return bOut; }
From source file:Main.java
public static byte[] des3EncodeCBC(byte[] key, byte[] keyiv, byte[] data) throws Exception { Key deskey = null;//from ww w .jav a 2s .c om DESedeKeySpec spec = new DESedeKeySpec(key); SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("desede"); deskey = keyfactory.generateSecret(spec); Cipher cipher = Cipher.getInstance("desede" + "/CBC/PKCS5Padding"); IvParameterSpec ips = new IvParameterSpec(keyiv); cipher.init(Cipher.ENCRYPT_MODE, deskey, ips); byte[] bOut = cipher.doFinal(data); return bOut; }
From source file:Main.java
public static byte[] des3DecodeCBC(byte[] key, byte[] keyiv, byte[] data) throws Exception { Key deskey = null;/*from w w w .j a va2 s. c o m*/ DESedeKeySpec spec = new DESedeKeySpec(key); SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("desede"); deskey = keyfactory.generateSecret(spec); Cipher cipher = Cipher.getInstance("desede" + "/CBC/PKCS5Padding"); IvParameterSpec ips = new IvParameterSpec(keyiv); cipher.init(Cipher.DECRYPT_MODE, deskey, ips); byte[] bOut = cipher.doFinal(data); return bOut; }
From source file:Main.java
public static byte[] TDesDec(byte[] key, byte[] in) throws Exception { Key deskey = null;// w ww . ja v a 2s. c o m byte[] tdesKey = new byte[24]; if (key.length % 8 != 0) return null; if (key.length == 8) { System.arraycopy(key, 0, tdesKey, 0, 8); System.arraycopy(key, 0, tdesKey, 8, 8); System.arraycopy(key, 0, tdesKey, 16, 8); } if (key.length == 16) { System.arraycopy(key, 0, tdesKey, 0, 16); System.arraycopy(key, 0, tdesKey, 16, 8); } DESedeKeySpec spec = new DESedeKeySpec(tdesKey); SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("desede"); deskey = keyfactory.generateSecret(spec); Cipher cipher = Cipher.getInstance("desede" + "/ECB/NoPadding"); cipher.init(Cipher.DECRYPT_MODE, deskey); byte[] bOut = cipher.doFinal(in); return bOut; }
From source file:Main.java
public static byte[] TDesEnc(byte[] key, byte[] in) throws Exception { Key deskey = null;/*from w ww. jav a 2s . c om*/ byte[] tdesKey = new byte[24]; if (key.length % 8 != 0) return null; if (key.length == 8) { System.arraycopy(key, 0, tdesKey, 0, 8); System.arraycopy(key, 0, tdesKey, 8, 8); System.arraycopy(key, 0, tdesKey, 16, 8); } if (key.length == 16) { System.arraycopy(key, 0, tdesKey, 0, 16); System.arraycopy(key, 0, tdesKey, 16, 8); } DESedeKeySpec spec = new DESedeKeySpec(tdesKey); SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("desede"); deskey = keyfactory.generateSecret(spec); Cipher cipher = Cipher.getInstance("desede" + "/ECB/NoPadding"); cipher.init(Cipher.ENCRYPT_MODE, deskey); byte[] bOut = cipher.doFinal(in); return bOut; }
From source file:Authentication.HashPassword.java
public HashPassword() throws Exception { myEncryptionKey = "ThisIsSpartaThisIsSparta"; myEncryptionScheme = DESEDE_ENCRYPTION_SCHEME; arrayBytes = myEncryptionKey.getBytes(UNICODE_FORMAT); ks = new DESedeKeySpec(arrayBytes); skf = SecretKeyFactory.getInstance(myEncryptionScheme); cipher = Cipher.getInstance(myEncryptionScheme); key = skf.generateSecret(ks);/*from w ww . ja va 2s .c o m*/ }
From source file:com.sds.acube.ndisc.xnapi.XNApiDesCipher.java
/** * ?<br>/*w w w . ja va 2 s.co m*/ * 3DES ?? 24bit KEY ?<br> * DES ?? 16bit KEY ?.<br> * * @return */ private static Key getKey() { String key = "x0134-ad17s658601j56-q75k2we0des-key".substring(0, 24); // ?? . try { DESedeKeySpec desKeySpec = new DESedeKeySpec(key.getBytes()); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede"); return keyFactory.generateSecret(desKeySpec); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.arwantech.docjavaui.utils.TripleDES.java
public TripleDES(String secretKey) throws Exception { myEncryptionKey = secretKey;//from w w w . j ava 2 s. c om myEncryptionScheme = DESEDE_ENCRYPTION_SCHEME; arrayBytes = myEncryptionKey.getBytes(UNICODE_FORMAT); ks = new DESedeKeySpec(arrayBytes); skf = SecretKeyFactory.getInstance(myEncryptionScheme); cipher = Cipher.getInstance(myEncryptionScheme); key = skf.generateSecret(ks); }