List of usage examples for javax.crypto Cipher DECRYPT_MODE
int DECRYPT_MODE
To view the source code for javax.crypto Cipher DECRYPT_MODE.
Click Source Link
From source file:com.amazonaws.cognito.sync.demo.client.server.AESEncryption.java
private static byte[] decrypt(byte[] cipherBytes, String key, byte[] iv) throws Exception { Cipher cipher = Cipher.getInstance(ENCRYPTION_ALGORITHM); AlgorithmParameters params = AlgorithmParameters.getInstance("AES"); params.init(new IvParameterSpec(iv)); cipher.init(Cipher.DECRYPT_MODE, getKey(key), params); return cipher.doFinal(cipherBytes); }
From source file:DesEncrypter.java
DesEncrypter(SecretKey key) throws Exception { byte[] iv = new byte[] { (byte) 0x8E, 0x12, 0x39, (byte) 0x9C, 0x07, 0x72, 0x6F, 0x5A }; AlgorithmParameterSpec paramSpec = new IvParameterSpec(iv); ecipher = Cipher.getInstance("DES/CBC/PKCS5Padding"); dcipher = Cipher.getInstance("DES/CBC/PKCS5Padding"); ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec); dcipher.init(Cipher.DECRYPT_MODE, key, paramSpec); }
From source file:com.aerohive.nms.engine.admin.task.licensemgr.license.processor2.PacketUtil.java
private static byte[] decryptData(byte[] bInput) { byte[] outBytes = null; try {//from www. ja v a 2 s. c o m Key key = new SecretKeySpec(secret_key, "DESede"); Cipher cipher = Cipher.getInstance("DESede", "SunJCE"); cipher.init(Cipher.DECRYPT_MODE, key, cipher.getParameters()); outBytes = cipher.doFinal(bInput); } catch (Exception ex) { //log.error("PacketUtil",ex.getMessage(), ex); return outBytes; } return outBytes; }
From source file:com.ro.ssc.app.client.licensing.TrialKeyValidator.java
public static String decodeKey(String encodedEncrypted) { String decoded = ""; try {//ww w .j a v a2s.co m byte[] saltDecrypt = SALT_DECRYPT.getBytes(StandardCharsets.UTF_8); SecretKeyFactory factoryKeyDecrypt = SecretKeyFactory.getInstance(SECRET_KEY_FACTORY); SecretKey tmp2 = factoryKeyDecrypt.generateSecret( new PBEKeySpec(PASS_DECRYPT.toCharArray(), saltDecrypt, ITERATIONS_DECRYPT, KEY_LENGTH)); SecretKeySpec decryptKey = new SecretKeySpec(tmp2.getEncoded(), ALGORITHM); Cipher aesCipherDecrypt = Cipher.getInstance(CIPHER); aesCipherDecrypt.init(Cipher.DECRYPT_MODE, decryptKey); byte[] e64bytes = StringUtils.getBytesUtf8(encodedEncrypted); byte[] eBytes = Base64.decodeBase64(e64bytes); byte[] cipherDecode = aesCipherDecrypt.doFinal(eBytes); decoded = StringUtils.newStringUtf8(cipherDecode); } catch (Exception e) { LOGGER.error("Error while decoding the trial key", e); } return decoded; }
From source file:info.fcrp.keepitsafe.util.Crypt.java
private static void init() { if (cryptCipher == null || decryptCipher == null) { try {//www . j ava 2 s . com SecretKeySpec keySpec = new SecretKeySpec(password.getBytes(), "AES"); cryptCipher = Cipher.getInstance("AES"); cryptCipher.init(Cipher.ENCRYPT_MODE, keySpec); decryptCipher = Cipher.getInstance("AES"); decryptCipher.init(Cipher.DECRYPT_MODE, keySpec); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } catch (NoSuchPaddingException e) { throw new RuntimeException(e); } // output = cipher.doFinal(input) // // Cipher c = Cipher.getInstance("AES"); // String plain = "plain"; // byte[] plainBytes = plain.getBytes(); // // c.init(Cipher.ENCRYPT_MODE, k); // c.update(plainBytes); // // byte[] encBytes = c.doFinal(); // String enc = Base64.encodeBase64String(encBytes); // assertNotSame(plain, enc); // // c.init(Cipher.DECRYPT_MODE, k); // c.update(encBytes); // byte[] decBytes = c.doFinal(); // String dec = new String(decBytes); catch (InvalidKeyException e) { throw new RuntimeException(e); } } }
From source file:com.imaginary.home.cloud.Configuration.java
static public @Nonnull String decrypt(@Nonnull String keySalt, @Nonnull String value) { try {//from w w w . jav a2 s . co m SecretKeySpec spec = new SecretKeySpec(getConfiguration().getCustomSalt(keySalt), "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, spec); byte[] b64 = value.getBytes("utf-8"); byte[] raw = Base64.decodeBase64(b64); byte[] decrypted = cipher.doFinal(raw); return new String(decrypted, "utf-8"); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.hp.application.automation.tools.EncryptionUtils.java
public static String Decrypt(String text, String key) throws Exception { Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); byte[] keyBytes = new byte[16]; byte[] b = key.getBytes("UTF-8"); int len = b.length; if (len > keyBytes.length) len = keyBytes.length;/* ww w. j a v a2 s .com*/ System.arraycopy(b, 0, keyBytes, 0, len); SecretKeySpec keySpec = new SecretKeySpec(keyBytes, "AES"); IvParameterSpec ivSpec = new IvParameterSpec(keyBytes); cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec); byte[] results = cipher.doFinal(Base64.decodeBase64(text)); return new String(results, "UTF-8"); }
From source file:hudson.util.Protector.java
/** * Returns null if fails to decrypt properly. *//*ww w . j a v a 2s .com*/ public static String unprotect(String data) { if (data == null) { return null; } try { Cipher cipher = Secret.getCipher(ALGORITHM); cipher.init(Cipher.DECRYPT_MODE, DES_KEY); String plainText = new String(cipher.doFinal(Base64.decodeBase64(data)), "UTF-8"); if (plainText.endsWith(MAGIC)) { return plainText.substring(0, plainText.length() - 3); } return null; } catch (GeneralSecurityException e) { return null; } catch (UnsupportedEncodingException e) { throw new Error(e); // impossible } catch (IOException e) { return null; } }
From source file:io.kahu.hawaii.util.encryption.CryptoUtil.java
public static String decrypt(String encrypted, String key, String initVector) throws ServerException { try {// w ww . j a va 2s . c o m Cipher cipher = initCipher(Cipher.DECRYPT_MODE, key, initVector); byte[] decrypted = cipher.doFinal(Base64.decodeBase64(encrypted)); return new String(decrypted); } catch (GeneralSecurityException e) { throw new ServerException(ServerError.ENCRYPTION, e); } }
From source file:com.esri.geoevent.datastore.Crypto.java
static public String doDecrypt(String stringToDecrypt) throws GeneralSecurityException { Cipher c = Cipher.getInstance(ALGO); c.init(Cipher.DECRYPT_MODE, encryptionKey); byte[] decodedValue = Base64.decodeBase64(stringToDecrypt.getBytes()); byte[] decryptedValue = c.doFinal(decodedValue); String decryptedString = new String(decryptedValue); return decryptedString; }