List of usage examples for javax.crypto Cipher ENCRYPT_MODE
int ENCRYPT_MODE
To view the source code for javax.crypto Cipher ENCRYPT_MODE.
Click Source Link
From source file:io.cloudslang.content.database.utils.TripleDES.java
static byte[] encryptString(final byte[] text) throws Exception { final SecretKey key = new SecretKeySpec( TripleDES.md5Hash("NpWsCaJQj1LaXt)YYnzr\\%zP~RydB*3YGutr*@|A\\ckG3\\Yf%k"), ENCRYPTION_KEYSPECTYPE); final Cipher cipher = Cipher.getInstance(ENCRYPTION_MODE); cipher.init(Cipher.ENCRYPT_MODE, key); return cipher.doFinal(text); }
From source file:com.web.mavenproject6.utility.EncryptionUtil.java
public byte[] encrypt(String input) throws GeneralSecurityException, NoSuchPaddingException { Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, skeySpec); return cipher.doFinal(input.getBytes()); }
From source file:Clases.cCifrado.java
public String Encriptar(String texto) { String secretKey = "MARSOFT"; //llave para encriptar datos String base64EncryptedString = ""; try {/*from w w w. j a va 2 s . c om*/ MessageDigest md = MessageDigest.getInstance("MD5"); byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8")); byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24); SecretKey key = new SecretKeySpec(keyBytes, "DESede"); Cipher cipher = Cipher.getInstance("DESede"); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] plainTextBytes = texto.getBytes("utf-8"); byte[] buf = cipher.doFinal(plainTextBytes); byte[] base64Bytes = Base64.encodeBase64(buf); base64EncryptedString = new String(base64Bytes); } catch (Exception ex) { return "Ha habido un problema enviando datos"; } return base64EncryptedString; }
From source file:info.bonjean.beluga.util.CryptoUtil.java
private static Cipher getCipher(String strKey, boolean encoder) { Cipher cipher = null;// w w w . j a v a 2 s . c o m if (encoder) cipher = encryptCiphers.get(strKey); else cipher = decryptCiphers.get(strKey); if (cipher != null) return cipher; try { SecretKeySpec key = new SecretKeySpec(strKey.getBytes(), "Blowfish"); cipher = Cipher.getInstance("Blowfish/ECB/NoPadding"); cipher.init(encoder ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE, key); if (encoder) encryptCiphers.put(strKey, cipher); else decryptCiphers.put(strKey, cipher); } catch (Exception e) { log.error(e.getMessage(), e); } return cipher; }
From source file:com.wso2telco.gsma.authenticators.cryptosystem.AESencrp.java
/** * Encrypt./* w ww . j a v a 2 s. c om*/ * * @param Data the data * @return the string * @throws Exception the exception */ public static String encrypt(String Data) throws Exception { Key key = generateKey(); Cipher c = Cipher.getInstance(ALGO); c.init(Cipher.ENCRYPT_MODE, key); byte[] encVal = c.doFinal(Data.getBytes()); //String encryptedValue = new BASE64Encoder().encode(encVal); byte[] encryptedValue = Base64.encodeBase64(encVal); return new String(encryptedValue); }
From source file:com.commander4j.util.JCipher.java
public String encrypt(String plainText) throws Exception { Cipher cipher = getCipher(Cipher.ENCRYPT_MODE); byte[] encryptedBytes = cipher.doFinal(plainText.getBytes()); return Base64.encodeBase64String(encryptedBytes); }
From source file:com.thoughtworks.go.server.util.EncryptionHelper.java
public static String encryptUsingRSA(String plainText, String publicKeyContent) throws InvalidKeyException, NoSuchPaddingException, NoSuchAlgorithmException, IOException, BadPaddingException, IllegalBlockSizeException, InvalidKeySpecException { Cipher encryptCipher = Cipher.getInstance("RSA"); encryptCipher.init(Cipher.ENCRYPT_MODE, getRSAPublicKeyFrom(publicKeyContent)); return Base64.getEncoder().encodeToString(encryptCipher.doFinal(plainText.getBytes(UTF_8))); }
From source file:com.wabacus.util.DesEncryptTools.java
public static String encrypt(String originalString) { if (originalString == null || originalString.trim().equals("")) return ""; if (KEY_OBJ == null) { log.warn(""); return originalString; }/*w w w.jav a 2 s .c o m*/ try { Cipher c1 = Cipher.getInstance(Algorithm); c1.init(Cipher.ENCRYPT_MODE, KEY_OBJ); return base64Encode(c1.doFinal(originalString.getBytes())); } catch (Exception e) { log.error("" + originalString + "", e); return null; } }
From source file:com.lecaddyfute.utils.security.AESCrypto.java
public static String encrypt(String Data) throws Exception { Key key = generateKey();/* w ww. jav a 2 s . c o m*/ Cipher c = Cipher.getInstance(ALGO); c.init(Cipher.ENCRYPT_MODE, key); byte[] encVal = c.doFinal(Data.getBytes()); String encryptedValue = new String(Base64.encodeBase64(encVal)); return encryptedValue; }
From source file:com.github.woki.payments.adyen.action.CSEUtil.java
static String encrypt(final Cipher aesCipher, final Cipher rsaCipher, final String plainText) throws BadPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException { SecretKey aesKey = aesKey(256); byte[] iv = iv(CSE_RANDOM, 12); aesCipher.init(Cipher.ENCRYPT_MODE, aesKey, new IvParameterSpec(iv)); byte[] encrypted = aesCipher.doFinal(plainText.getBytes()); byte[] result = new byte[iv.length + encrypted.length]; System.arraycopy(iv, 0, result, 0, iv.length); System.arraycopy(encrypted, 0, result, iv.length, encrypted.length); byte[] encryptedAESKey; try {// w w w . j a va2 s. co m encryptedAESKey = rsaCipher.doFinal(aesKey.getEncoded()); } catch (ArrayIndexOutOfBoundsException e) { throw new InvalidKeyException(e.getMessage()); } return String.format("%s%s%s%s%s%s", CSE_PREFIX, CSE_VERSION, CSE_SEPARATOR, Base64.encodeBase64String(encryptedAESKey), CSE_SEPARATOR, Base64.encodeBase64String(result)); }