1 package org.apache.turbine.services.crypto.provider; 2 3 18 19 import java.security.MessageDigest ; 20 21 import org.apache.commons.codec.base64.Base64; 22 23 import org.apache.turbine.services.crypto.CryptoAlgorithm; 24 25 42 public class JavaCrypt 43 implements CryptoAlgorithm 44 { 45 46 47 public static final String DEFAULT_CIPHER = "SHA"; 48 49 50 private String cipher = null; 51 52 55 public JavaCrypt() 56 { 57 this.cipher = DEFAULT_CIPHER; 58 } 59 60 70 public void setCipher(String cipher) 71 { 72 this.cipher = cipher; 73 } 74 75 81 public void setSeed(String seed) 82 { 83 84 } 85 86 93 public String encrypt(String value) 94 throws Exception 95 { 96 MessageDigest md = MessageDigest.getInstance(cipher); 97 98 byte[] digest = md.digest(value.getBytes("UTF-8")); 101 102 byte[] encodedDigest = Base64.encode(digest); 104 return (encodedDigest == null ? null : new String (encodedDigest)); 105 } 106 107 } 108 | Popular Tags |