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:com.agiletec.aps.util.DefaultApsEncrypter.java
public static Key getKey() { try {/*from w w w.j a v a2 s . c o m*/ byte[] bytes = KEY_STRING.getBytes(); DESedeKeySpec pass = new DESedeKeySpec(bytes); SecretKeyFactory skf = SecretKeyFactory.getInstance(TRIPLE_DES_KEY_SPEC); SecretKey s = skf.generateSecret(pass); return s; } catch (Throwable t) { throw new RuntimeException("Error creating key", t); } }
From source file:com.seer.datacruncher.utils.CryptoUtil.java
public CryptoUtil() { try {//from www . jav a2 s.co m String myEncryptionKey = cryWorm(Reserved.ENCRYPTIONKEY, Reserved.CHECK, 0); String myEncryptionSchema = DESEDE_ENCRYPTION_SCHEMA; byte[] keyAsBytes = myEncryptionKey.getBytes(UNICODE_FORMAT); KeySpec myKeySpec = new DESedeKeySpec(keyAsBytes); SecretKeyFactory mySecretKeyFactory = SecretKeyFactory.getInstance(myEncryptionSchema); cipher = Cipher.getInstance(myEncryptionSchema); key = mySecretKeyFactory.generateSecret(myKeySpec); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.marvelution.jira.plugins.hudson.encryption.StringEncrypter.java
/** * Constructor/*from w w w . j a v a 2 s . c o m*/ */ public StringEncrypter() { try { keySpec = new DESedeKeySpec(DEFAULT_ENCRYPTION_KEY.getBytes(UNICODE_FORMAT)); keyFactory = SecretKeyFactory.getInstance(DESEDE_ENCRYPTION_SCHEME); cipher = Cipher.getInstance(DESEDE_ENCRYPTION_SCHEME); } catch (Exception e) { LOGGER.fatal("Failed to initilise String Encryption classes. Reason: " + e.getMessage(), e); throw new StringEncryptionException( "Failed to initilise String Encryption classes. Reason: " + e.getMessage(), e); } }
From source file:com.anteam.demo.codec.cipher.symmetric.DESedeCoder.java
/** * //from w w w. j av a 2 s.c om */ public DESedeCoder() { super(); try { keySpec = new DESedeKeySpec(key); } catch (InvalidKeyException e) { LOG.error("DESedeKeySpec:" + key, e); } }
From source file:net.navasoft.madcoin.backend.services.security.Encrypter.java
/** * Instantiates a new encrypter./*from ww w. ja v a 2s . co m*/ * * @param keyString * the key string * @param ivString * the iv string * @since 5/08/2014, 08:03:33 PM */ public Encrypter(String keyString, String ivString) { try { final MessageDigest md = MessageDigest.getInstance("md5"); final byte[] digestOfPassword = md.digest(Base64.decodeBase64(keyString.getBytes("utf-8"))); final byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24); for (int j = 0, k = 16; j < 8;) { keyBytes[k++] = keyBytes[j++]; } keySpec = new DESedeKeySpec(keyBytes); key = SecretKeyFactory.getInstance("DESede").generateSecret(keySpec); iv = new IvParameterSpec(ivString.getBytes()); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.paxxis.cornerstone.encryption.TripleDESEncryptionHandler.java
public void initialize() { if (encryptionKeyFile != null) { try {/*from w ww. j ava 2s. c om*/ FileReader fr = new FileReader(encryptionKeyFile); int cnt; char[] cbuf = new char[256]; StringBuilder builder = new StringBuilder(); while (-1 != (cnt = fr.read(cbuf, 0, 256))) { String s = new String(cbuf, 0, cnt); builder.append(s); } encryptionKey = builder.toString(); } catch (Exception e) { throw new RuntimeException(e); } } if (encryptionKey == null) { throw new RuntimeException("No Encryption Key"); } try { byte[] arrayBytes = encryptionKey.getBytes(UNICODE_FORMAT); KeySpec ks = new DESedeKeySpec(arrayBytes); SecretKeyFactory skf = SecretKeyFactory.getInstance(DESEDE_ENCRYPTION_SCHEME); cipher = Cipher.getInstance(DESEDE_ENCRYPTION_SCHEME); key = skf.generateSecret(ks); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:Main.java
/** * * Creates a SecretKey from an encoded DESedeKeySpec * //from w w w. jav a 2 s. c om * @param rawkey * @return * @throws InvalidKeyException * @throws NoSuchAlgorithmException * @throws InvalidKeySpecException */ public static SecretKey createSecretKey(byte[] rawkey) throws InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException { DESedeKeySpec keyspec = new DESedeKeySpec(rawkey); SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("DESede"); return keyfactory.generateSecret(keyspec); }
From source file:es.juntadeandalucia.framework.ticket.impl.DefaultTicket.java
public DefaultTicket(Configuration config) throws Exception { try {//from w w w . j av a 2s . c o m ticketLifeTime = config.getLong(TIME_TICKET_LIFETIME, 0); } catch (Exception e) { e = new Exception(msg.getString("ticket.error.lifetimeerror")); //$NON-NLS-1$ log.warn(e); throw e; } List<?> textKey = config.getList(TICKET_KEY); try { SecretKeyFactory kf = SecretKeyFactory.getInstance("DESede"); key = kf.generateSecret(new DESedeKeySpec(hexToByte(textKey))); } catch (Exception e) { e = new Exception(msg.getString("ticket.error.keycreationerror")); //$NON-NLS-1$ log.warn(e); throw e; } }
From source file:com.rootcloud.ejb.RootCloudBean.java
public String encryptThreeDESECB(String src, String key) throws Exception { DESedeKeySpec dks = new DESedeKeySpec(key.getBytes("UTF-8")); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede"); javax.crypto.SecretKey securekey = keyFactory.generateSecret(dks); Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding"); cipher.init(1, securekey);//from w w w . j av a 2 s. c o m byte b[] = cipher.doFinal(src.getBytes()); Encoder ec = java.util.Base64.getEncoder(); return ec.encodeToString(b); }
From source file:it.scoppelletti.programmerpower.security.spi.DESedeKeyFactory.java
@Override protected KeySpec getKeySpec(String alg, KeyRep.Type keyType, Properties props, String prefix) { String name, value;/* www . j a v a 2s . com*/ byte[] key; KeySpec keySpec; name = Strings.concat(prefix, DESedeKeyFactory.PROP_KEY); value = props.getProperty(name); if (Strings.isNullOrEmpty(value)) { throw new ArgumentNullException(name); } try { key = Hex.decodeHex(value.toCharArray()); } catch (DecoderException ex) { throw SecurityUtils.toSecurityException(ex); } try { keySpec = new DESedeKeySpec(key); } catch (InvalidKeyException ex) { throw SecurityUtils.toSecurityException(ex); } return keySpec; }