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:eap.util.EDcodeUtil.java
public static String desDecodeForHexAsString(String dataHex, String key) { return utf8Decode(des(hexDecode(dataHex), utf8Encode(key), Cipher.DECRYPT_MODE)); }
From source file:com.fujitsu.dc.common.auth.token.LocalToken.java
/** * ??./*w w w .j a va2 s .c om*/ * @param in ? * @param ivBytes * @return ??? * @throws AbstractOAuth2Token.TokenParseException */ public static String decode(final String in, final byte[] ivBytes) throws AbstractOAuth2Token.TokenParseException { byte[] inBytes = DcCoreUtils.decodeBase64Url(in); Cipher cipher; try { cipher = Cipher.getInstance(AES_CBC_PKCS5_PADDING); } catch (NoSuchAlgorithmException e) { throw AbstractOAuth2Token.PARSE_EXCEPTION; } catch (NoSuchPaddingException e) { throw AbstractOAuth2Token.PARSE_EXCEPTION; } try { cipher.init(Cipher.DECRYPT_MODE, aesKey, new IvParameterSpec(ivBytes)); } catch (InvalidKeyException e) { throw AbstractOAuth2Token.PARSE_EXCEPTION; } catch (InvalidAlgorithmParameterException e) { throw AbstractOAuth2Token.PARSE_EXCEPTION; } byte[] plainBytes; try { plainBytes = cipher.doFinal(inBytes); } catch (IllegalBlockSizeException e) { throw AbstractOAuth2Token.PARSE_EXCEPTION; } catch (BadPaddingException e) { throw AbstractOAuth2Token.PARSE_EXCEPTION; } try { return new String(plainBytes, CharEncoding.UTF_8); } catch (UnsupportedEncodingException e) { throw AbstractOAuth2Token.PARSE_EXCEPTION; } }
From source file:io.personium.common.auth.token.LocalToken.java
/** * ??./*from ww w.java2s .c o m*/ * @param in ? * @param ivBytes * @return ??? * @throws AbstractOAuth2Token.TokenParseException */ public static String decode(final String in, final byte[] ivBytes) throws AbstractOAuth2Token.TokenParseException { byte[] inBytes = PersoniumCoreUtils.decodeBase64Url(in); Cipher cipher; try { cipher = Cipher.getInstance(AES_CBC_PKCS5_PADDING); } catch (NoSuchAlgorithmException e) { throw AbstractOAuth2Token.PARSE_EXCEPTION; } catch (NoSuchPaddingException e) { throw AbstractOAuth2Token.PARSE_EXCEPTION; } try { cipher.init(Cipher.DECRYPT_MODE, aesKey, new IvParameterSpec(ivBytes)); } catch (InvalidKeyException e) { throw AbstractOAuth2Token.PARSE_EXCEPTION; } catch (InvalidAlgorithmParameterException e) { throw AbstractOAuth2Token.PARSE_EXCEPTION; } byte[] plainBytes; try { plainBytes = cipher.doFinal(inBytes); } catch (IllegalBlockSizeException e) { throw AbstractOAuth2Token.PARSE_EXCEPTION; } catch (BadPaddingException e) { throw AbstractOAuth2Token.PARSE_EXCEPTION; } try { return new String(plainBytes, CharEncoding.UTF_8); } catch (UnsupportedEncodingException e) { throw AbstractOAuth2Token.PARSE_EXCEPTION; } }
From source file:com.eucalyptus.crypto.StringCrypto.java
public String decrypt(String passwordEncoded) throws GeneralSecurityException { //String withoutPrefix = passwordEncoded.substring(VMwareBrokerProperties.ENCRYPTION_FORMAT.length(), passwordEncoded.length()); byte[] passwordEncrypted = UrlBase64.decode(passwordEncoded); Key pk = keystore.getKey(ALIAS, PASSWORD); Cipher cipher = Cipher.getInstance(this.asymmetricFormat, this.provider); cipher.init(Cipher.DECRYPT_MODE, pk, Crypto.getSecureRandomSupplier().get()); return new String(cipher.doFinal(passwordEncrypted)); }
From source file:gemlite.core.util.RSAUtils.java
/** * <P>// w w w . ja v a2 s . c o m * ? * </p> * * @param encryptedData * ? * @param privateKey * ?(BASE64?) * @return * @throws Exception */ public static byte[] decryptByPrivateKey(byte[] encryptedData, String privateKey) throws Exception { byte[] keyBytes = Base64Utils.decode(privateKey); PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes); KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); Key privateK = keyFactory.generatePrivate(pkcs8KeySpec); Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm()); cipher.init(Cipher.DECRYPT_MODE, privateK); int inputLen = encryptedData.length; ByteArrayOutputStream out = new ByteArrayOutputStream(); int offSet = 0; byte[] cache; int i = 0; // ? while (inputLen - offSet > 0) { if (inputLen - offSet > MAX_DECRYPT_BLOCK) { cache = cipher.doFinal(encryptedData, offSet, MAX_DECRYPT_BLOCK); } else { cache = cipher.doFinal(encryptedData, offSet, inputLen - offSet); } out.write(cache, 0, cache.length); i++; offSet = i * MAX_DECRYPT_BLOCK; } byte[] decryptedData = out.toByteArray(); out.close(); return decryptedData; }
From source file:uploadProcess.java
public static boolean decrypt(File inputFolder, String fileName, String patientID) { try {/*from ww w. j a v a2 s.c om*/ //Download File from Cloud.. DropboxUpload download = new DropboxUpload(); download.downloadFile(fileName, StoragePath.getDropboxDir() + patientID, inputFolder); String ukey = GetKey.getPatientKey(patientID); File inputFile = new File(inputFolder.getAbsolutePath() + File.separator + fileName); FileInputStream fis = new FileInputStream(inputFile); File outputFolder = new File(inputFolder.getAbsolutePath() + File.separator + "temp"); if (!outputFolder.exists()) { outputFolder.mkdir(); } FileOutputStream fos = new FileOutputStream(outputFolder.getAbsolutePath() + File.separator + fileName); byte[] k = ukey.getBytes(); SecretKeySpec key = new SecretKeySpec(k, "AES"); Cipher enc = Cipher.getInstance("AES"); enc.init(Cipher.DECRYPT_MODE, key); CipherOutputStream cos = new CipherOutputStream(fos, enc); byte[] buf = new byte[1024]; int read; while ((read = fis.read(buf)) != -1) { cos.write(buf, 0, read); } fis.close(); fos.flush(); cos.close(); return true; } catch (Exception e) { System.out.println("Error: " + e); } return false; }
From source file:com.rsmart.kuali.kfs.sys.context.PropertyLoadingFactoryBean.java
/** * Decrypts encrypted values in properties. Interprets that any property in the {@link Properties} instance * provided with a key ending with the {@code ENCRYPTED_PROPERTY_EXTENSION} is considered to be encrypted. * It is then decrypted and replaced with a key of the same name only using the {@code PASSWORD_PROPERTY_EXTENSION} * /*from w w w.j av a2 s . com*/ * @param props the {@link Properties} to decrypt * @throws {@link Exception} if there's any problem decrypting/encrypting properties. */ protected void decryptProps(final Properties props) throws Exception { final String keystore = props.getProperty(KEYSTORE_LOCATION_PROPERTY); final String storepass = props.getProperty(KEYSTORE_PASSWORD_PROPERTY); final FileInputStream fs = new FileInputStream(keystore); final KeyStore jks = KeyStore.getInstance(KEYSTORE_TYPE); jks.load(fs, storepass.toCharArray()); fs.close(); final Cipher cipher = Cipher.getInstance(ENCRYPTION_STRATEGY); cipher.init(Cipher.DECRYPT_MODE, (PrivateKey) jks.getKey(RICE_RSA_KEY_NAME, storepass.toCharArray())); for (final String key : props.stringPropertyNames()) { if (key.endsWith(ENCRYPTED_PROPERTY_EXTENSION)) { final String prefix = key.substring(0, key.indexOf(ENCRYPTED_PROPERTY_EXTENSION)); final String encrypted_str = props.getProperty(key); props.setProperty(prefix + PASSWORD_PROPERTY_EXTENSION, new String(cipher.doFinal(new BASE64Decoder().decodeBuffer(encrypted_str)))); } } }
From source file:eap.util.EDcodeUtil.java
public static String desDecodeForBase64AsString(String dataBase64, String key) { return utf8Decode(des(Base64.decodeBase64(utf8Encode(dataBase64)), utf8Encode(key), Cipher.DECRYPT_MODE)); }
From source file:com.cyberninjas.xerobillableexpenses.util.Settings.java
private String decryptText(String cipherText) { try {//from ww w. java 2 s . c om this.iv = prefs.getByteArray("DRUGS", null); if (this.iv == null) return ""; byte[] cText = Base64.decodeBase64(cipherText); /* Decrypt the message, given derived key and initialization vector. */ cipher.init(Cipher.DECRYPT_MODE, this.secret, new IvParameterSpec(this.iv)); String ret = new String(cipher.doFinal(cText), "UTF-8"); return ret; } catch (IllegalBlockSizeException | BadPaddingException | UnsupportedEncodingException | InvalidKeyException | InvalidAlgorithmParameterException ex) { Logger.getLogger(RSAx509CertGen.class.getName()).log(Level.SEVERE, null, ex); } return ""; }