本文整理汇总了Java中ch.ethz.ssh2.crypto.Base64类的典型用法代码示例。如果您正苦于以下问题:Java Base64类的具体用法?Java Base64怎么用?Java Base64使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Base64类属于ch.ethz.ssh2.crypto包,在下文中一共展示了Base64类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: addHostkeyToFile
import ch.ethz.ssh2.crypto.Base64; //导入依赖的package包/类
/**
* Adds a single public key entry to the a known_hosts file.
* This method is designed to be used in a {@link ServerHostKeyVerifier}.
*
* @param knownHosts the file where the publickey entry will be appended.
* @param hostnames a list of hostname patterns - at least one most be specified. Check out the
* OpenSSH sshd man page for a description of the pattern matching algorithm.
* @param serverHostKeyAlgorithm as passed to the {@link ServerHostKeyVerifier}.
* @param serverHostKey as passed to the {@link ServerHostKeyVerifier}.
* @throws IOException
*/
public final static void addHostkeyToFile(File knownHosts, String[] hostnames, String serverHostKeyAlgorithm,
byte[] serverHostKey) throws IOException {
if ((hostnames == null) || (hostnames.length == 0))
throw new IllegalArgumentException("Need at least one hostname specification");
if ((serverHostKeyAlgorithm == null) || (serverHostKey == null))
throw new IllegalArgumentException();
CharArrayWriter writer = new CharArrayWriter();
for (int i = 0; i < hostnames.length; i++) {
if (i != 0)
writer.write(',');
writer.write(hostnames[i]);
}
writer.write(' ');
writer.write(serverHostKeyAlgorithm);
writer.write(' ');
writer.write(Base64.encode(serverHostKey));
writer.write("\n");
char[] entry = writer.toCharArray();
RandomAccessFile raf = new RandomAccessFile(knownHosts, "rw");
long len = raf.length();
if (len > 0) {
raf.seek(len - 1);
int last = raf.read();
if (last != '\n')
raf.write('\n');
}
raf.write(new String(entry).getBytes());
raf.close();
}
开发者ID:fast-data-transfer,项目名称:fdt,代码行数:50,代码来源:KnownHosts.java
示例2: checkHashed
import ch.ethz.ssh2.crypto.Base64; //导入依赖的package包/类
private final boolean checkHashed(String entry, String hostname) {
if (entry.startsWith("|1|") == false)
return false;
int delim_idx = entry.indexOf('|', 3);
if (delim_idx == -1)
return false;
String salt_base64 = entry.substring(3, delim_idx);
String hash_base64 = entry.substring(delim_idx + 1);
byte[] salt = null;
byte[] hash = null;
try {
salt = Base64.decode(salt_base64.toCharArray());
hash = Base64.decode(hash_base64.toCharArray());
} catch (IOException e) {
return false;
}
SHA1 sha1 = new SHA1();
if (salt.length != sha1.getDigestLength())
return false;
byte[] dig = hmacSha1Hash(salt, hostname);
for (int i = 0; i < dig.length; i++)
if (dig[i] != hash[i])
return false;
return true;
}
开发者ID:fast-data-transfer,项目名称:fdt,代码行数:36,代码来源:KnownHosts.java
示例3: initialize
import ch.ethz.ssh2.crypto.Base64; //导入依赖的package包/类
private void initialize(char[] knownHostsData) throws IOException {
BufferedReader br = new BufferedReader(new CharArrayReader(knownHostsData));
while (true) {
String line = br.readLine();
if (line == null)
break;
line = line.trim();
if (line.startsWith("#"))
continue;
String[] arr = line.split(" ");
if (arr.length >= 3) {
if ((arr[1].compareTo("ssh-rsa") == 0) || (arr[1].compareTo("ssh-dss") == 0)) {
String[] hostnames = arr[0].split(",");
byte[] msg = Base64.decode(arr[2].toCharArray());
addHostkey(hostnames, arr[1], msg);
}
}
}
}
开发者ID:fast-data-transfer,项目名称:fdt,代码行数:28,代码来源:KnownHosts.java
示例4: generateUserKey
import ch.ethz.ssh2.crypto.Base64; //导入依赖的package包/类
public static UserKey generateUserKey() throws NoSuchAlgorithmException, NoSuchProviderException, IOException
{
KeyPairGenerator kpg = SecurityUtils.getKeyPairGenerator("RSA");
kpg.initialize(1024, new SecureRandom());
java.security.KeyPair kp = kpg.generateKeyPair();
String priv = getKeyMaterial(kp.getPrivate());
byte[] encoded = encode((RSAPublicKey) kp.getPublic());
return new UserKey().setPrivateKeyMaterial(priv)
.setPublicKeyMaterial(new String(Base64.encode(encoded)))
.setFingerPrint(getFingerPrint((RSAPublicKey) kp.getPublic()));
}
开发者ID:alessandroleite,项目名称:dohko,代码行数:16,代码来源:SecurityUtils2.java
示例5: readPublicKey
import ch.ethz.ssh2.crypto.Base64; //导入依赖的package包/类
public static PublicKey readPublicKey(@Nonnull File key) throws IOException, GeneralSecurityException
{
String[] contents = IOUtils2.readLines(key).split(" ");
checkArgument(contents.length == 3, "Invalid RSA public key");
org.apache.commons.codec.binary.Base64 b64 = new org.apache.commons.codec.binary.Base64();
return readPublicKey(b64.decode(contents[1]));
}
开发者ID:alessandroleite,项目名称:dohko,代码行数:8,代码来源:SecurityUtils2.java
示例6: checkHashed
import ch.ethz.ssh2.crypto.Base64; //导入依赖的package包/类
private final boolean checkHashed(String entry, String hostname)
{
if (entry.startsWith("|1|") == false)
return false;
int delim_idx = entry.indexOf('|', 3);
if (delim_idx == -1)
return false;
String salt_base64 = entry.substring(3, delim_idx);
String hash_base64 = entry.substring(delim_idx + 1);
byte[] salt = null;
byte[] hash = null;
try
{
salt = Base64.decode(salt_base64.toCharArray());
hash = Base64.decode(hash_base64.toCharArray());
}
catch (IOException e)
{
return false;
}
SHA1 sha1 = new SHA1();
if (salt.length != sha1.getDigestLength())
return false;
byte[] dig = hmacSha1Hash(salt, hostname);
for (int i = 0; i < dig.length; i++)
if (dig[i] != hash[i])
return false;
return true;
}
开发者ID:mattb243,项目名称:AmazonEC2Matlab,代码行数:40,代码来源:KnownHosts.java
示例7: initialize
import ch.ethz.ssh2.crypto.Base64; //导入依赖的package包/类
private void initialize(char[] knownHostsData) throws IOException
{
BufferedReader br = new BufferedReader(new CharArrayReader(knownHostsData));
while (true)
{
String line = br.readLine();
if (line == null)
break;
line = line.trim();
if (line.startsWith("#"))
continue;
String[] arr = line.split(" ");
if (arr.length >= 3)
{
if ((arr[1].compareTo("ssh-rsa") == 0) || (arr[1].compareTo("ssh-dss") == 0))
{
String[] hostnames = arr[0].split(",");
byte[] msg = Base64.decode(arr[2].toCharArray());
addHostkey(hostnames, arr[1], msg);
}
}
}
}
开发者ID:mattb243,项目名称:AmazonEC2Matlab,代码行数:32,代码来源:KnownHosts.java
示例8: 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);
}
开发者ID:mattb243,项目名称:AmazonEC2Matlab,代码行数:23,代码来源:KnownHosts.java
示例9: addHostkeyToFile
import ch.ethz.ssh2.crypto.Base64; //导入依赖的package包/类
/**
* Adds a single public key entry to the a known_hosts file.
* This method is designed to be used in a {@link ServerHostKeyVerifier}.
*
* @param knownHosts the file where the publickey entry will be appended.
* @param hostnames a list of hostname patterns - at least one most be specified. Check out the
* OpenSSH sshd man page for a description of the pattern matching algorithm.
* @param serverHostKeyAlgorithm as passed to the {@link ServerHostKeyVerifier}.
* @param serverHostKey as passed to the {@link ServerHostKeyVerifier}.
* @throws IOException
*/
public final static void addHostkeyToFile(File knownHosts, String[] hostnames, String serverHostKeyAlgorithm,
byte[] serverHostKey) throws IOException
{
if ((hostnames == null) || (hostnames.length == 0))
throw new IllegalArgumentException("Need at least one hostname specification");
if ((serverHostKeyAlgorithm == null) || (serverHostKey == null))
throw new IllegalArgumentException();
CharArrayWriter writer = new CharArrayWriter();
for (int i = 0; i < hostnames.length; i++)
{
if (i != 0)
writer.write(',');
writer.write(hostnames[i]);
}
writer.write(' ');
writer.write(serverHostKeyAlgorithm);
writer.write(' ');
writer.write(Base64.encode(serverHostKey));
writer.write("\n");
char[] entry = writer.toCharArray();
RandomAccessFile raf = new RandomAccessFile(knownHosts, "rw");
long len = raf.length();
if (len > 0)
{
raf.seek(len - 1);
int last = raf.read();
if (last != '\n')
raf.write('\n');
}
raf.write(StringEncoder.GetBytes(new String(entry)));
raf.close();
}
开发者ID:mattb243,项目名称:AmazonEC2Matlab,代码行数:53,代码来源:KnownHosts.java
示例10: addHostkeyToFile
import ch.ethz.ssh2.crypto.Base64; //导入依赖的package包/类
/**
* Adds a single public key entry to the a known_hosts file.
* This method is designed to be used in a {@link ServerHostKeyVerifier}.
*
* @param knownHosts the file where the publickey entry will be appended.
* @param hostnames a list of hostname patterns - at least one most be specified. Check out the
* OpenSSH sshd man page for a description of the pattern matching algorithm.
* @param serverHostKeyAlgorithm as passed to the {@link ServerHostKeyVerifier}.
* @param serverHostKey as passed to the {@link ServerHostKeyVerifier}.
* @throws IOException
*/
public final static void addHostkeyToFile(File knownHosts, String[] hostnames, String serverHostKeyAlgorithm,
byte[] serverHostKey) throws IOException
{
if ((hostnames == null) || (hostnames.length == 0))
throw new IllegalArgumentException("Need at least one hostname specification");
if ((serverHostKeyAlgorithm == null) || (serverHostKey == null))
throw new IllegalArgumentException();
CharArrayWriter writer = new CharArrayWriter();
for (int i = 0; i < hostnames.length; i++)
{
if (i != 0)
writer.write(',');
writer.write(hostnames[i]);
}
writer.write(' ');
writer.write(serverHostKeyAlgorithm);
writer.write(' ');
writer.write(Base64.encode(serverHostKey));
writer.write("\n");
char[] entry = writer.toCharArray();
RandomAccessFile raf = new RandomAccessFile(knownHosts, "rw");
long len = raf.length();
if (len > 0)
{
raf.seek(len - 1);
int last = raf.read();
if (last != '\n')
raf.write('\n');
}
raf.write(new String(entry).getBytes());
raf.close();
}
开发者ID:mattb243,项目名称:AmazonEC2Matlab,代码行数:53,代码来源:KnownHosts.java
示例11: 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);
}
开发者ID:fast-data-transfer,项目名称:fdt,代码行数:22,代码来源:KnownHosts.java
示例12: 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());
}
开发者ID:ezScrum,项目名称:ezScrum,代码行数:31,代码来源:LogonSubmitAction.java
注:本文中的ch.ethz.ssh2.crypto.Base64类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论