1 package com.opencms.legacy; 2 3 import org.opencms.i18n.CmsMessageContainer; 4 import org.opencms.security.CmsDefaultPasswordHandler; 5 import org.opencms.security.CmsPasswordEncryptionException; 6 import org.opencms.security.I_CmsPasswordHandler; 7 import org.opencms.security.Messages; 8 9 import java.io.UnsupportedEncodingException ; 10 import java.security.MessageDigest ; 11 import java.security.NoSuchAlgorithmException ; 12 13 14 17 public class CmsLegacyPasswordHandler extends CmsDefaultPasswordHandler { 18 19 22 public String digest (String password, String digestType, String inputEncoding) throws CmsPasswordEncryptionException { 23 24 MessageDigest md; 25 byte[] result; 26 27 try { 28 if (I_CmsPasswordHandler.DIGEST_TYPE_PLAIN.equals(digestType.toLowerCase())) { 29 result = password.getBytes(inputEncoding); 30 } else { 31 md = MessageDigest.getInstance(digestType); 32 33 md.reset(); 34 md.update(password.getBytes(inputEncoding)); 35 result = md.digest(); 36 } 37 } catch (NoSuchAlgorithmException e) { 38 CmsMessageContainer message = Messages.get().container(Messages.ERR_UNSUPPORTED_ALGORITHM_1, digestType); 39 throw new CmsPasswordEncryptionException(message, e); 40 } catch (UnsupportedEncodingException e) { 41 CmsMessageContainer message = Messages.get().container(Messages.ERR_UNSUPPORTED_PASSWORD_ENCODING_1, inputEncoding); 42 throw new CmsPasswordEncryptionException(message, e); 43 } 44 45 StringBuffer buf = new StringBuffer (); 46 String addZerro; 47 for (int i = 0; i < result.length; i++) { 48 addZerro = Integer.toHexString(128 + result[i]); 49 if (addZerro.length() < 2) { 50 addZerro = '0' + addZerro; 51 } 52 buf.append(addZerro); 53 } 54 return buf.toString(); 55 } 56 } 57
| Popular Tags
|