Java源码示例:ch.ethz.ssh2.crypto.Base64

示例1
public InputStream getData() {
	try {
		var decoded = Base64.decode(this.data.toCharArray());
		ByteArrayInputStream bis = new ByteArrayInputStream(decoded);
		return new GZIPInputStream(bis);
	} catch (IOException e) {
		e.printStackTrace();
	}
	return null;
}
 
示例2
/**
 * Attempt to instantiate an SSH public key from the specified file
 * which contains a single public key.
 * @param sshPublicKeyFile
 * @return RSAPublicKey or DSAPublicKey
 * @throws FileNotFoundException key file not found
 * @throws IOException if key file not found or key parse failed
 * @see RSAPublicKey
 * @see DSAPublicKey
 */
public static Object getSSHPublicKey(File sshPublicKeyFile) throws IOException {

	BufferedReader r = new BufferedReader(new FileReader(sshPublicKeyFile));
	String keyLine = null;
	String line;
	while ((line = r.readLine()) != null) {
		if (!line.startsWith("ssh-")) {
			continue;
		}
		keyLine = line;
		break;
	}
	r.close();

	if (keyLine != null) {
		String[] pieces = keyLine.split(" ");
		if (pieces.length >= 2) {
			byte[] pubkeyBytes = Base64.decode(pieces[1].toCharArray());
			if ("ssh-rsa".equals(pieces[0])) {
				return RSASHA1Verify.decodeSSHRSAPublicKey(pubkeyBytes);
			}
			else if ("ssh-dsa".equals(pieces[0])) {
				return DSASHA1Verify.decodeSSHDSAPublicKey(pubkeyBytes);
			}
		}
	}

	throw new IOException(
		"Invalid SSH public key file, valid ssh-rsa or ssh-dsa entry not found: " +
			sshPublicKeyFile);
}
 
示例3
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());
}