james邮件服务器对用户的密码进行了加密。
默认使用的方式是“SHA”。
可以找到加密和解密的源码
package org.apache.james.security;
import javax.mail.MessagingException;
import javax.mail.internet.MimeUtility;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Locale;
public class DigestUtil {
public static void main(String[] args) {
//...
}
public static void printUsage() {
//...
}
public static void digestFile(String filename, String algorithm) {
byte[] b = new byte[65536];
int count = 0;
int read = 0;
FileInputStream fis = null;
FileOutputStream fos = null;
try {
MessageDigest md = MessageDigest.getInstance(algorithm);
fis = new FileInputStream(filename);
while (fis.available() > 0) {
read = fis.read(b);
md.update(b, 0, read);
count += read;
}
byte[] digest = md.digest();
StringBuffer fileNameBuffer =
new StringBuffer(128)
.append(filename)
.append(".")
.append(algorithm);
fos = new FileOutputStream(fileNameBuffer.toString());
OutputStream encodedStream = MimeUtility.encode(fos, "base64");
encodedStream.write(digest);
fos.flush();
} catch (Exception e) {
System.out.println("Error computing Digest: " + e);
} finally {
try {
fis.close();
fos.close();
} catch (Exception ignored) {}
}
}
public static String digestString(String pass, String algorithm )
throws NoSuchAlgorithmException {
MessageDigest md;
ByteArrayOutputStream bos;
try {
md = MessageDigest.getInstance(algorithm);
byte[] digest = md.digest(pass.getBytes("iso-8859-1"));
bos = new ByteArrayOutputStream();
OutputStream encodedStream = MimeUtility.encode(bos, "base64");
encodedStream.write(digest);
return bos.toString("iso-8859-1");
} catch (IOException ioe) {
throw new RuntimeException("Fatal error: " + ioe);
} catch (MessagingException me) {
throw new RuntimeException("Fatal error: " + me);
}
}
private DigestUtil() {
}
}
仿照源码加入相应的jar包即可对密码进行加密解密。
转载于:https://blog.51cto.com/3892131/1343293