1 package org.apache.turbine.services.crypto.provider; 2 3 18 19 import java.io.ByteArrayOutputStream ; 20 import java.io.OutputStream ; 21 22 import java.security.MessageDigest ; 23 24 import javax.mail.internet.MimeUtility ; 25 26 import org.apache.turbine.services.crypto.CryptoAlgorithm; 27 28 45 public class OldJavaCrypt 46 implements CryptoAlgorithm 47 { 48 49 50 public static final String DEFAULT_CIPHER = "SHA"; 51 52 53 private String cipher = null; 54 55 58 public OldJavaCrypt() 59 { 60 this.cipher = DEFAULT_CIPHER; 61 } 62 63 73 public void setCipher(String cipher) 74 { 75 this.cipher = cipher; 76 } 77 78 84 public void setSeed(String seed) 85 { 86 87 } 88 89 96 public String encrypt(String value) 97 throws Exception 98 { 99 MessageDigest md = MessageDigest.getInstance(cipher); 100 101 104 byte[] digest = md.digest(value.getBytes("UTF-8")); 105 ByteArrayOutputStream bas = 106 new ByteArrayOutputStream (digest.length + digest.length / 3 + 1); 107 OutputStream encodedStream = MimeUtility.encode(bas, "base64"); 108 encodedStream.write(digest); 109 return bas.toString(); 110 } 111 112 } 113 | Popular Tags |