1 package com.tdsecurities.itracker.security; 2 3 import java.security.MessageDigest ; 4 import java.security.NoSuchAlgorithmException ; 5 6 9 public class EncryptData 10 { 11 12 private static String ENCRYPT_TYPE_MD = "MD5"; 13 14 19 public static String md5(String _cleardata) 20 { 21 String _encryptData = null; 22 { 23 try 25 { 26 MessageDigest _messageDigest = 28 MessageDigest.getInstance(ENCRYPT_TYPE_MD); 29 30 _messageDigest.reset(); 32 33 34 _messageDigest.update(_cleardata.getBytes()); 36 37 byte[] _digestedData = _messageDigest.digest(); 39 StringBuffer _strBuffer = new StringBuffer (); 40 for (int _i = 0; _i < _digestedData.length; _i++) 41 { 42 _strBuffer.append(Integer.toHexString(0xFF & _digestedData[_i])); 43 _strBuffer.append(" "); 44 } 45 _encryptData = _strBuffer.toString(); 46 } 47 catch (NoSuchAlgorithmException _nosuchalgorithmException) 48 { 49 System.out.println( 50 "EncryptData:md5 Failed to get cryptographic algorithm" 51 + _nosuchalgorithmException); 52 } 53 catch (NullPointerException _nullpointerException) 54 { 55 System.out.println( 56 "EncryptData:md5: NullPointerException while encrypting data." 57 + _nullpointerException); 58 } 59 } 60 return _encryptData; 61 } 62 63 64 public static void main(String [] args) 65 { 66 String password = "pass004"; 67 String encrypted = EncryptData.md5(password); 68 System.out.println(encrypted); 69 } 70 71 } 72 | Popular Tags |