Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
0000738: AbstractSymmetricEngine should call init() method of the Sec…
…urityService
  • Loading branch information
chenson42 committed Jul 27, 2012
1 parent 6e4dddf commit cee942b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Expand Up @@ -291,7 +291,9 @@ public static ISecurityService createSecurityService(TypedProperties properties)
try {
String className = properties.get(ParameterConstants.CLASS_NAME_SECURITY_SERVICE,
SecurityService.class.getName());
return (ISecurityService) Class.forName(className).newInstance();
ISecurityService securityService = (ISecurityService) Class.forName(className).newInstance();
securityService.init();
return securityService;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
Expand Down
Expand Up @@ -21,6 +21,7 @@

package org.jumpmind.symmetric.service.impl;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.security.KeyStore;
Expand All @@ -38,6 +39,7 @@
import javax.crypto.spec.PBEParameterSpec;

import org.apache.commons.codec.binary.Base64;
import org.jumpmind.exception.IoException;
import org.jumpmind.symmetric.common.SecurityConstants;
import org.jumpmind.symmetric.common.SystemConstants;
import org.jumpmind.symmetric.service.ISecurityService;
Expand All @@ -57,22 +59,37 @@ public class SecurityService implements ISecurityService {

public void init() {
}


protected void checkThatKeystoreFileExists() {
String keyStoreLocation = System.getProperty(SystemConstants.SYSPROP_KEYSTORE);
if (!new File(keyStoreLocation).exists()) {
throw new IoException(
"Could not find the keystore file. We expected it to exist here: "
+ keyStoreLocation);
}
}

public String encrypt(String plainText) {
try {
checkThatKeystoreFileExists();
byte[] bytes = plainText.getBytes(SecurityConstants.CHARSET);
byte[] enc = getCipher(Cipher.ENCRYPT_MODE).doFinal(bytes);
return new String(Base64.encodeBase64(enc), SecurityConstants.CHARSET);
} catch (Exception e) {
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}

public String decrypt(String encText) {
try {
checkThatKeystoreFileExists();
byte[] dec = Base64.decodeBase64(encText.getBytes());
byte[] bytes = getCipher(Cipher.DECRYPT_MODE).doFinal(dec);
return new String(bytes, SecurityConstants.CHARSET);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit cee942b

Please sign in to comment.