use of com.adaptris.security.exc.PasswordException in project interlok by adaptris.
the class CoreSecurityService method initService.
@Override
protected final void initService() throws CoreException {
try {
pkPassword = getPrivateKeyPasswordProvider().retrievePrivateKeyPassword();
} catch (PasswordException e) {
throw new CoreException("Could not get password using " + getPrivateKeyPasswordProvider().getClass().getCanonicalName(), e);
}
try {
if (isEmpty(localPartner)) {
throw new CoreException("No Local Partner configured");
}
localPartnerAlias = new Alias(localPartner, pkPassword);
if (isEmpty(remotePartner)) {
log.warn("Remote partner not configured, " + "must be set individually as message metadata");
} else {
remotePartnerAlias = new Alias(remotePartner);
}
SecurityServiceFactory factory = securityFactory;
if (factory == null) {
factory = SecurityServiceFactory.defaultInstance();
}
service = factory.createService();
for (Iterator i = keystoreUrls.iterator(); i.hasNext(); ) {
ConfiguredKeystore url = (ConfiguredKeystore) i.next();
service.registerKeystore(url);
}
service.setEncryptionAlgorithm(encryptionAlgorithm);
if (successId != null && failId != null) {
branchingEnabled = true;
} else {
log.debug("No Success Id or Fail Id, branching disabled");
}
} catch (AdaptrisSecurityException e) {
throw new CoreException(e);
}
}
use of com.adaptris.security.exc.PasswordException in project interlok by adaptris.
the class FtpPasswordConnectionCase method testConnect_BadEncodedPassword.
@Test
public void testConnect_BadEncodedPassword() throws Exception {
Assume.assumeTrue(areTestsEnabled());
FileTransferConnectionUsingPassword connection = (FileTransferConnectionUsingPassword) createConnection();
connection.setDefaultPassword("PW:BHFYENGMWEYQ");
try {
start(connection);
FileTransferClient client = connection.connect(getDestinationString());
fail();
} catch (IOException | PasswordException expected) {
} finally {
stop(connection);
}
}
use of com.adaptris.security.exc.PasswordException in project interlok by adaptris.
the class AesCrypto method encode.
@Override
@SuppressWarnings({ "lgtm [java/weak-cryptographic-algorithm]" })
public String encode(String plainText, String charset) throws PasswordException {
String result = null;
try {
KeyGenerator kg = KeyGenerator.getInstance(ALG);
kg.init(KEY_LEN, SecurityUtil.getSecureRandom());
SecretKey sessionKey = kg.generateKey();
Cipher dataCipher = Cipher.getInstance(CIPHER);
dataCipher.init(Cipher.ENCRYPT_MODE, sessionKey);
byte[] encryptedBody = dataCipher.doFinal(seed(plainText, charset));
Output output = new Output();
output.setSessionKey(sessionKey.getEncoded());
output.setSessionVector(dataCipher.getIV());
output.setEncryptedData(encryptedBody);
result = PORTABLE_PASSWORD + output.write();
} catch (Exception e) {
throw new PasswordException(e);
}
return result;
}
use of com.adaptris.security.exc.PasswordException in project interlok by adaptris.
the class MicrosoftCrypto method decode.
public String decode(String encrypted, String charset) throws PasswordException {
String encryptedString = encrypted;
String result;
if (encrypted.startsWith(MSCAPI_STYLE)) {
encryptedString = encrypted.substring(MSCAPI_STYLE.length());
}
try {
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.DECRYPT_MODE, getPrivateKey());
byte[] encryptedBytes = base64.translate(encryptedString);
byte[] decrypted = cipher.doFinal(encryptedBytes);
result = new String(decrypted, getEncodingToUse(charset));
} catch (Exception e) {
throw new PasswordException(e);
}
return result;
}
use of com.adaptris.security.exc.PasswordException in project interlok by adaptris.
the class PbeCrypto method encode.
@Override
@SuppressWarnings({ "lgtm [java/weak-cryptographic-algorithm]" })
public String encode(String plainText, String charset) throws PasswordException {
byte[] encrypted = new byte[0];
try {
PBEParameterSpec pbeParamSpec = new PBEParameterSpec(SALT, ITERATIONS);
PBEKeySpec pbeKeySpec = new PBEKeySpec(hostname.toCharArray());
SecretKeyFactory keyFac = SecretKeyFactory.getInstance(ALGORITHM);
SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);
Cipher pbeCipher = Cipher.getInstance(ALGORITHM);
pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);
encrypted = pbeCipher.doFinal(seed(plainText, charset));
} catch (Exception e) {
throw new PasswordException(e);
}
return NON_PORTABLE_PASSWORD + base64.translate(encrypted);
}
Aggregations