Skip to content

Commit

Permalink
small tweak on Password Codec
Browse files Browse the repository at this point in the history
  • Loading branch information
clebertsuconic committed Jul 10, 2012
1 parent 8e820f2 commit 3e8ba4f
Showing 1 changed file with 4 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@
*/
public class DefaultSensitiveStringCodec implements SensitiveDataCodec<String>
{
private byte[] KEY_BYTES = "clusterpassword".getBytes();
private byte[] internalKey = "clusterpassword".getBytes();

public String decode(Object secret) throws NoSuchPaddingException,
NoSuchAlgorithmException,
InvalidKeyException,
BadPaddingException,
IllegalBlockSizeException
{
SecretKeySpec key = new SecretKeySpec(KEY_BYTES, "Blowfish");
SecretKeySpec key = new SecretKeySpec(internalKey, "Blowfish");

BigInteger n = new BigInteger((String)secret, 16);
byte[] encoding = n.toByteArray();
Expand Down Expand Up @@ -81,21 +81,14 @@ public Object encode(String secret) throws NoSuchPaddingException,
BadPaddingException,
IllegalBlockSizeException
{
SecretKeySpec key = new SecretKeySpec(KEY_BYTES, "Blowfish");
SecretKeySpec key = new SecretKeySpec(internalKey, "Blowfish");

Cipher cipher = Cipher.getInstance("Blowfish");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] encoding = cipher.doFinal(secret.getBytes());
BigInteger n = new BigInteger(encoding);
return n.toString(16);
}

public static void main(String[] args) throws Exception
{
DefaultSensitiveStringCodec codec = new DefaultSensitiveStringCodec();
Object encode = codec.encode(args[0]);
System.out.println("Encoded password: " + encode);
}

public void init(Map<String, String> params)
{
Expand All @@ -108,7 +101,7 @@ public void init(Map<String, String> params)

private void updateKey(String key)
{
KEY_BYTES = key.getBytes();
this.internalKey = key.getBytes();
}


Expand Down

0 comments on commit 3e8ba4f

Please sign in to comment.