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.tydic.dbp.utils.ThreeDesUtils.java
public static String decryptMode(String srcStr) { try {//w w w . ja va 2 s .c om // ? SecretKey deskey = new SecretKeySpec(keyBytes, Algorithm); // Cipher c1 = Cipher.getInstance(Algorithm); c1.init(Cipher.DECRYPT_MODE, deskey); return new String(c1.doFinal(Hex.decodeHex(srcStr.toCharArray()))); } catch (java.security.NoSuchAlgorithmException e1) { e1.printStackTrace(); } catch (javax.crypto.NoSuchPaddingException e2) { e2.printStackTrace(); } catch (java.lang.Exception e3) { e3.printStackTrace(); } return null; }
From source file:de.serverfrog.pw.crypt.SerpentUtil.java
public static CipherInputStream getInputStream(InputStream os, Key key) throws IOException { try {/*from w w w . j a v a2 s .com*/ Cipher instance = Cipher.getInstance("Serpent", "BC"); instance.init(Cipher.DECRYPT_MODE, key); return new CipherInputStream(os, instance); } catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchProviderException | NoSuchPaddingException ex) { if (ex.getClass().equals(InvalidKeyException.class)) { throw new IOException("Password Wrong"); } Logger.getLogger(SerpentUtil.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:love.sola.netsupport.util.RSAUtil.java
public static String decrypt(String encrypted) { try {//w ww. ja v a2 s.c om Cipher cipher = Cipher.getInstance("RSA"); cipher.init(Cipher.DECRYPT_MODE, privateKey); byte[] original = cipher.doFinal(Base64.decodeBase64(encrypted)); return new String(original, StandardCharsets.UTF_8); } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:illab.nabal.util.SecurityHelper.java
/** * Decrypt a AES-encrypted message./* w w w.j av a 2 s . c o m*/ * * @param encrypted * @return String * @throws Exception */ public static String decipher(String encrypted) throws Exception { if (StringHelper.isEmpty(encrypted) == false) { Cipher cipher = Cipher.getInstance(AES); cipher.init(Cipher.DECRYPT_MODE, SYSTEM_SECRET_KEY_SPEC); return new String(cipher.doFinal(Base64.decode(encrypted, Base64.DEFAULT)), HTTP.UTF_8); } else { return null; } }
From source file:com.security.ch08_rsa.RSACoderTextKey.java
/** * ?//from w w w . j ava 2s. c o m * * @param data * ? * @param key * ? * @return byte[] ? * @throws Exception */ private static byte[] decryptByPrivateKey(byte[] data, byte[] key) throws Exception { // ?? PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(key); KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); // ?? PrivateKey privateKey = keyFactory.generatePrivate(pkcs8KeySpec); // ? Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm()); cipher.init(Cipher.DECRYPT_MODE, privateKey); return cipher.doFinal(data); }
From source file:com.searchbox.utils.DecryptLicense.java
public static byte[] decrypt(byte[] inpBytes) throws Exception { byte[] pkbytes = Base64.decodeBase64(privkey); KeyFactory keyFactory = KeyFactory.getInstance(algorithm); PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(pkbytes); PrivateKey pk = keyFactory.generatePrivate(privateKeySpec); Cipher cipher = Cipher.getInstance(xform); cipher.init(Cipher.DECRYPT_MODE, pk); return cipher.doFinal(inpBytes); }
From source file:Componentes.EncryptionMD5.java
public static String Desencriptar(String encriptado) { System.out.println(encriptado); String secretKey = "qualityinfosolutions"; //llave para encriptar datos String base64EncryptedString = ""; try {/*from w w w.j a va 2s .c o m*/ System.out.println("h"); byte[] message = Base64.decodeBase64(encriptado.getBytes("utf-8")); System.out.println("b"); MessageDigest md = MessageDigest.getInstance("MD5"); System.out.println("a"); byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8")); System.out.println("c"); byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24); System.out.println("g"); SecretKey key = new SecretKeySpec(keyBytes, "DESede"); System.out.println("w"); Cipher decipher = Cipher.getInstance("DESede"); System.out.println("t"); decipher.init(Cipher.DECRYPT_MODE, key); System.out.println("r"); System.out.println(Arrays.toString(message)); byte[] plainText = decipher.doFinal(message); System.out.println(Arrays.toString(plainText)); base64EncryptedString = new String(plainText, "UTF-8"); } catch (Exception ex) { ex.printStackTrace(); } return base64EncryptedString; }
From source file:com.sirius.utils.encrypt.DESEncryptor.java
@Override public byte[] decrypt(Object key, byte[] data) throws EncryptException { try {/*w w w . j av a 2 s. c o m*/ Cipher cipher = Cipher.getInstance(ALGORITHM, security_provider); cipher.init(Cipher.DECRYPT_MODE, getKey(key)); return cipher.doFinal(data); } catch (Exception e) { throw new EncryptException(e); } }
From source file:com.jsmartframework.web.manager.CsrfEncrypter.java
private static Cipher getDecryptCipher(HttpServletRequest request, String key) throws Exception { Cipher decryptCipher = (Cipher) request.getAttribute(REQUEST_CSRF_DECRYPT_CIPHER); if (decryptCipher == null) { decryptCipher = Cipher.getInstance("AES"); SecretKey secretKey = new SecretKeySpec(key.getBytes("UTF8"), "AES"); decryptCipher.init(Cipher.DECRYPT_MODE, secretKey); request.setAttribute(REQUEST_CSRF_DECRYPT_CIPHER, decryptCipher); }/* w w w .j av a2 s .co m*/ return decryptCipher; }
From source file:com.jsmartframework.web.manager.AuthEncrypter.java
private static Cipher getDecryptCipher(HttpServletRequest request, String key) throws Exception { Cipher decryptCipher = (Cipher) request.getAttribute(REQUEST_AUTH_DECRYPT_CIPHER); if (decryptCipher == null) { decryptCipher = Cipher.getInstance("AES"); SecretKey secretKey = new SecretKeySpec(key.getBytes("UTF8"), "AES"); decryptCipher.init(Cipher.DECRYPT_MODE, secretKey); request.setAttribute(REQUEST_AUTH_DECRYPT_CIPHER, decryptCipher); }/* w ww .j ava2 s . c om*/ return decryptCipher; }