1 package org.apache.turbine.services.crypto.provider; 2 3 18 19 import org.apache.turbine.services.crypto.CryptoAlgorithm; 20 21 27 public class UnixCrypt 28 implements CryptoAlgorithm 29 { 30 31 32 private String seed = null; 33 34 35 private static final char[] SALT_CHARS = 36 (("abcdefghijklmnopqrstuvwxyz" 37 + "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./").toCharArray()); 38 39 42 public UnixCrypt() 43 { 44 } 45 46 54 public void setCipher(String cipher) 55 { 56 57 } 58 59 66 public void setSeed(String seed) 67 { 68 this.seed = seed; 69 } 70 71 78 public String encrypt(String value) 79 throws Exception 80 { 81 if (seed == null) 82 { 83 java.util.Random randomGenerator = new java.util.Random (); 84 int numSaltChars = SALT_CHARS.length; 85 86 seed = (new StringBuffer ()) 87 .append(SALT_CHARS[Math.abs(randomGenerator.nextInt()) 88 % numSaltChars]) 89 .append(SALT_CHARS[Math.abs(randomGenerator.nextInt()) 90 % numSaltChars]) 91 .toString(); 92 } 93 94 95 return new cryptix.tools.UnixCrypt(seed).crypt(value); 96 } 97 98 } 99 | Popular Tags |