Hello, I need solve a script Please check below code. if you are expert please give comments with your mobile numbers. I can not run this code here show some errors.
Thanks
Code
=====
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import sun.misc.BASE64Encoder;
public final class MyPasswordEncrypt {
public static synchronized String encrypt(String plaintext,
String algorithm, String encoding) throws Exception {
MessageDigest msgDigest = null;
String hashValue = null;
try {
msgDigest = MessageDigest.getInstance(algorithm);
msgDigest.update(plaintext.getBytes(encoding));
byte rawByte[] = msgDigest.digest();
hashValue = (new BASE64Encoder()).encode(rawByte);
} catch (NoSuchAlgorithmException e) {
System.out.println(No Such Algorithm Exists);
} catch (UnsupportedEncodingException e) {
System.out.println(The Encoding Is Not Supported);
}
return hashValue;
}
public static void main(String args[]) throws Exception {
String plainPassword = SecretPassword;
System.out.println(PlainText\\tAlgo\\tEncoding\\tEncrypted Password);
System.out.println(plainPassword + \\tSHA\\tUTF-8\\t
+ encrypt(MySecretPassword, SHA, UTF-8));
System.out.println(plainPassword + \\tSHA-1\\tUTF-16\\t
+ encrypt(MySecretPassword, SHA-1, UTF-16));
System.out.println(plainPassword + \\tMD5\\tUTF-8\\t
+ encrypt(MySecretPassword, MD5, UTF-8));
System.out.println(plainPassword + \\tMD5\\tUTF-16\\t
+ encrypt(MySecretPassword, MD5, UTF-16));
}
}
OutPUt
-----------------------------------------
PlainText Algo Encoding Encrypted Password
SecretPassword SHA UTF-8 lScpxhyrfgHktfW6e5WDDSB190s=
SecretPassword SHA-1 UTF-16 NfsACTQRTvkEV5kzrDY55vQR1ec=
SecretPassword MD5 UTF-8 cxWgEuytEFmjY0+L4TR4Rg==
SecretPassword MD5 UTF-16 JulkQ6YpxzLMlpIgU28xmg==