本文整理汇总了Java中ch.ethz.ssh2.crypto.Base64.encode方法的典型用法代码示例。如果您正苦于以下问题:Java Base64.encode方法的具体用法?Java Base64.encode怎么用?Java Base64.encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ch.ethz.ssh2.crypto.Base64
的用法示例。
在下文中一共展示了Base64.encode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createHashedHostname
import ch.ethz.ssh2.crypto.Base64; //导入方法依赖的package包/类
/**
* Generate the hashed representation of the given hostname. Useful for adding entries
* with hashed hostnames to a known_hosts file. (see -H option of OpenSSH key-gen).
*
* @param hostname
* @return the hashed representation, e.g., "|1|cDhrv7zwEUV3k71CEPHnhHZezhA=|Xo+2y6rUXo2OIWRAYhBOIijbJMA="
*/
public static final String createHashedHostname(String hostname)
{
SHA1 sha1 = new SHA1();
byte[] salt = new byte[sha1.getDigestLength()];
new SecureRandom().nextBytes(salt);
byte[] hash = hmacSha1Hash(salt, hostname);
String base64_salt = new String(Base64.encode(salt));
String base64_hash = new String(Base64.encode(hash));
return new String("|1|" + base64_salt + "|" + base64_hash);
}
示例2: createHashedHostname
import ch.ethz.ssh2.crypto.Base64; //导入方法依赖的package包/类
/**
* Generate the hashed representation of the given hostname. Useful for adding entries
* with hashed hostnames to a known_hosts file. (see -H option of OpenSSH key-gen).
*
* @param hostname
* @return the hashed representation, e.g., "|1|cDhrv7zwEUV3k71CEPHnhHZezhA=|Xo+2y6rUXo2OIWRAYhBOIijbJMA="
*/
public static final String createHashedHostname(String hostname) {
SHA1 sha1 = new SHA1();
byte[] salt = new byte[sha1.getDigestLength()];
new SecureRandom().nextBytes(salt);
byte[] hash = hmacSha1Hash(salt, hostname);
String base64_salt = new String(Base64.encode(salt));
String base64_hash = new String(Base64.encode(hash));
return new String("|1|" + base64_salt + "|" + base64_hash);
}
示例3: execute
import ch.ethz.ssh2.crypto.Base64; //导入方法依赖的package包/类
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
LogonForm logonForm = (LogonForm) form;
// 取得登入的使用者帳號密碼
String userId = logonForm.getUserId();
String password = logonForm.getPassword();
log.debug("LogonForm.UserID=" + userId);
// 建立User Session
IUserSession userSession = ProjectInfoCenter.getInstance().login(userId, password);
String encodedPassword = new String(Base64.encode(password.getBytes()));
// 設定權限資訊
AccessPermissionManager.setupPermission(request, userSession);
// 設定User Session
request.getSession().setAttribute("UserSession", userSession);
// 為了要讓插件中可以使用session的中使用者的密碼,所以將原本利用MD5加密的密碼轉換成利用Base64加密。如此加密的密碼才可逆
request.getSession().setAttribute("passwordForPlugin", encodedPassword);
ProjectLogic projectLogic = new ProjectLogic();
projectLogic.cloneDefaultFile();
Person person = this.getPerson(userSession.getAccount());
return mapping.findForward(person.getForwardName());
}