public static String decryptString(String keyStorePath, String keyAlias, KeyStorePasswordCallback passwordCallback, byte[] encrypted) throws GeneralSecurityException, IOException { byte[] decrypted = decrypt(keyStorePath, keyAlias, passwordCallback, encrypted); return new String(decrypted, CHARSET_ENCODING); }
public static byte[] encryptString(String keyStorePath, String keyAlias, KeyStorePasswordCallback passwordCallback, String value) throws GeneralSecurityException, IOException { return encrypt(keyStorePath, keyAlias, passwordCallback, value.getBytes(CHARSET_ENCODING)); }
public static byte[] decrypt(String keyStorePath, String keyAlias, KeyStorePasswordCallback passwordCallback, byte[] encrypted) throws GeneralSecurityException, IOException { Key secretKey = getSymmetricKey(keyStorePath, keyAlias, passwordCallback); Cipher cipher = Cipher.getInstance(PADDING_MECHANISM); cipher.init(Cipher.DECRYPT_MODE, secretKey, new IvParameterSpec(new byte[16])); return cipher.doFinal(encrypted); }
public static AiravataAPI getAPI(URI registryURL, String gateway, String username, String trustStoreFilePath, String trustStorePassword) throws AiravataAPIInvocationException{ SecurityUtil.setTrustStoreParameters(trustStoreFilePath, trustStorePassword); return getAPI(registryURL, gateway, username, username); }
if (password != null && !password.equals("")) { try { user.setPassword(SecurityUtil.digestString(password, ServerSettings.getSetting("default.registry.password.hash.method"))); } catch (NoSuchAlgorithmException e) { if (password != null && !password.equals("")) { try { existingUser.setPassword(SecurityUtil.digestString(password, ServerSettings.getSetting("default.registry.password.hash.method"))); } catch (NoSuchAlgorithmException e) {
public static KeyStore loadKeyStore(String keyStoreFilePath, String keyStoreType, KeyStorePasswordCallback passwordCallback) throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException { java.io.FileInputStream fis = null; try { fis = new java.io.FileInputStream(keyStoreFilePath); return loadKeyStore(fis, keyStoreType, passwordCallback); } finally { if (fis != null) { fis.close(); } } }
public static void initializeTrustStore() throws ApplicationSettingsException { SecurityUtil.setTrustStoreParameters(getTrustStorePath(), getTrustStorePassword()); }
if (password != null && !password.equals("")) { try { user.setPassword(SecurityUtil.digestString(password, ServerSettings.getSetting("default.registry.password.hash.method"))); } catch (NoSuchAlgorithmException e) { if (password != null && !password.equals("")) { try { existingUser.setPassword(SecurityUtil.digestString(password, ServerSettings.getSetting("default.registry.password.hash.method"))); existingUser.setGatewayId(gateway.getGatewayId());
private static Key getSymmetricKey(String keyStorePath, String keyAlias, KeyStorePasswordCallback passwordCallback) throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, UnrecoverableKeyException { KeyStore ks = SecurityUtil.loadKeyStore(keyStorePath, "jceks", passwordCallback); if (ks == null) { throw new IOException("Unable to load Java keystore " + keyStorePath); } return ks.getKey(keyAlias, passwordCallback.getSecretKeyPassPhrase(keyAlias)); }
public Object convertByteArrayToObject(byte[] data) throws CredentialStoreException { ObjectInputStream objectInputStream = null; Object o = null; try { try { //decrypt the data first if (encrypt()) { data = SecurityUtil.decrypt(this.keyStorePath, this.secretKeyAlias, this.keyStorePasswordCallback, data); } objectInputStream = new ObjectInputStream(new ByteArrayInputStream(data)); o = objectInputStream.readObject(); } catch (IOException e) { throw new CredentialStoreException("Error de-serializing object.", e); } catch (ClassNotFoundException e) { throw new CredentialStoreException("Error de-serializing object.", e); } catch (GeneralSecurityException e) { throw new CredentialStoreException("Error decrypting data.", e); } } finally { if (objectInputStream != null) { try { objectInputStream.close(); } catch (IOException e) { log.error("Error occurred while closing the stream", e); } } } return o; }
byte[] array = byteArrayOutputStream.toByteArray(); try { return SecurityUtil.encrypt(this.keyStorePath, this.secretKeyAlias, this.keyStorePasswordCallback, array); } catch (GeneralSecurityException e) { throw new CredentialStoreException("Error encrypting data", e);
public static byte[] encrypt(String keyStorePath, String keyAlias, KeyStorePasswordCallback passwordCallback, byte[] value) throws GeneralSecurityException, IOException { Key secretKey = getSymmetricKey(keyStorePath, keyAlias, passwordCallback); Cipher cipher = Cipher.getInstance(PADDING_MECHANISM); cipher.init(Cipher.ENCRYPT_MODE, secretKey, new IvParameterSpec(new byte[16])); return cipher.doFinal(value); }