当前位置: 首页>>代码示例>>Java>>正文


Java Base64类代码示例

本文整理汇总了Java中com.trilead.ssh2.crypto.Base64的典型用法代码示例。如果您正苦于以下问题:Java Base64类的具体用法?Java Base64怎么用?Java Base64使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Base64类属于com.trilead.ssh2.crypto包,在下文中一共展示了Base64类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createHashedHostname

import com.trilead.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)
{
	MessageDigest sha1;
	try {
		sha1 = MessageDigest.getInstance("SHA1");
	} catch (NoSuchAlgorithmException e) {
		throw new RuntimeException("VM doesn't support SHA1", e);
	}

	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:dragonlinux,项目名称:connectbot,代码行数:28,代码来源:KnownHosts.java

示例2: writeLogTo

import com.trilead.ssh2.crypto.Base64; //导入依赖的package包/类
@Override
public long writeLogTo(long start, int size, Writer w) throws IOException {
    if (isHtml()) {
        ConsoleAnnotationOutputStream caw = new ConsoleAnnotationOutputStream(w, this.createAnnotator(Stapler.getCurrentRequest()), this.context, this.charset);
        long r = super.writeLogTo(start, size, caw);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Cipher sym = PASSING_ANNOTATOR.encrypt();
        ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(new CipherOutputStream(baos, sym)));
        oos.writeLong(System.currentTimeMillis());
        oos.writeObject(caw.getConsoleAnnotator());
        oos.close();
        StaplerResponse rsp = Stapler.getCurrentResponse();
        if(rsp != null) {
            rsp.setHeader("X-ConsoleAnnotator", new String(Base64.encode(baos.toByteArray())));
        }
        return r;
    } else {
        return super.writeLogTo(start, size, w);
    }
}
 
开发者ID:fabric8io,项目名称:fabric8-jenkins-workflow-steps,代码行数:21,代码来源:AnnotatedLargeText.java

示例3: importPEM

import com.trilead.ssh2.crypto.Base64; //导入依赖的package包/类
public static KeyPair importPEM (String pem) {
       byte [] encoded   = null;
	KeyPair recovered = null;

	// Get rid of any header and footer.
       String privKeyPEM = pem.replace("-----BEGIN RSA PRIVATE KEY-----\n", "");
       privKeyPEM = privKeyPEM.replace("-----END RSA PRIVATE KEY-----", "");
       privKeyPEM = privKeyPEM.replace("-----BEGIN DSA PRIVATE KEY-----\n", "");
       privKeyPEM = privKeyPEM.replace("-----END DSA PRIVATE KEY-----", "");
       privKeyPEM = privKeyPEM.replace("-----BEGIN PRIVATE KEY-----\n", "");
       privKeyPEM = privKeyPEM.replace("-----END PRIVATE KEY-----", "");

       try {
      		encoded = android.util.Base64.decode(privKeyPEM, android.util.Base64.DEFAULT);      	
       	recovered = recoverKeyPair(encoded);
	} catch (Exception e) {
		Log.e (TAG, "Could not recover keypair from PEM string.");
		e.printStackTrace();
		return null;
	}
	return recovered;
}
 
开发者ID:runsoftdev,项目名称:bVnc,代码行数:23,代码来源:PubkeyUtils.java

示例4: importPkcs8

import com.trilead.ssh2.crypto.Base64; //导入依赖的package包/类
public static KeyPair importPkcs8 (String pem) throws Exception {
       byte [] encoded   = null;
	KeyPair recovered = null;

	// Get rid of any header and footer.
       String privKeyPEM = pem.replace(PKCS8_START + "\n", "");
       privKeyPEM = privKeyPEM.replace(PKCS8_END,          "");

       try {
      		encoded = android.util.Base64.decode(privKeyPEM, android.util.Base64.DEFAULT);      	
          	recovered = recoverKeyPair(encoded);
	} catch (Exception e) {
		Log.e (TAG, "Could not recover keypair from PKCS8 string.");
		e.printStackTrace();
	}
	return recovered;
}
 
开发者ID:runsoftdev,项目名称:bVnc,代码行数:18,代码来源:PubkeyUtils.java

示例5: readPKCS8Key

import com.trilead.ssh2.crypto.Base64; //导入依赖的package包/类
private KeyPair readPKCS8Key(byte[] keyData) {
	BufferedReader reader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(keyData)));

	// parse the actual key once to check if its encrypted
	// then save original file contents into our database
	try {
		ByteArrayOutputStream keyBytes = new ByteArrayOutputStream();

		String line;
		boolean inKey = false;
		while ((line = reader.readLine()) != null) {
			if (line.equals(PubkeyUtils.PKCS8_START)) {
				inKey = true;
			} else if (line.equals(PubkeyUtils.PKCS8_END)) {
				break;
			} else if (inKey) {
				keyBytes.write(line.getBytes("US-ASCII"));
			}
		}

		if (keyBytes.size() > 0) {
			byte[] decoded = Base64.decode(keyBytes.toString().toCharArray());

			return PubkeyUtils.recoverKeyPair(decoded);
		}
	} catch (Exception e) {
		return null;
	}
	return null;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:31,代码来源:PubkeyListActivity.java

示例6: append

import com.trilead.ssh2.crypto.Base64; //导入依赖的package包/类
public XmlBuilder append(String field, Object data) {
	if (data == null) {
		sb.append(String.format("<%s/>", field));
	} else if (data instanceof String) {
		String input = (String) data;
		boolean binary = false;

		for (byte b : input.getBytes()) {
			if (b < 0x20 || b > 0x7e) {
				binary = true;
				break;
			}
		}

		sb.append(String.format("<%s>%s</%s>", field,
				binary ? new String(Base64.encode(input.getBytes())) : input, field));
	} else if (data instanceof Integer) {
		sb.append(String.format("<%s>%d</%s>", field, (Integer) data, field));
	} else if (data instanceof Long) {
		sb.append(String.format("<%s>%d</%s>", field, (Long) data, field));
	} else if (data instanceof byte[]) {
		sb.append(String.format("<%s>%s</%s>", field, new String(Base64.encode((byte[]) data)), field));
	} else if (data instanceof Boolean) {
		sb.append(String.format("<%s>%s</%s>", field, (Boolean) data, field));
	}

	return this;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:29,代码来源:XmlBuilder.java

示例7: initialize

import com.trilead.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:dragonlinux,项目名称:connectbot,代码行数:32,代码来源:KnownHosts.java

示例8: checkHashed

import com.trilead.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:jskierbi,项目名称:intellij-ce-playground,代码行数:40,代码来源:KnownHosts.java

示例9: checkHashed

import com.trilead.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:jianlinwei,项目名称:sshtunnel,代码行数:36,代码来源:KnownHosts.java

示例10: initialize

import com.trilead.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:jianlinwei,项目名称:sshtunnel,代码行数:30,代码来源:KnownHosts.java

示例11: writeHtmlTo

import com.trilead.ssh2.crypto.Base64; //导入依赖的package包/类
public long writeHtmlTo(long start, Writer w) throws IOException {
    ConsoleAnnotationOutputStream caw = new ConsoleAnnotationOutputStream(w, this.createAnnotator(Stapler.getCurrentRequest()), this.context, this.charset);
    long r = super.writeLogTo(start, caw);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Cipher sym = PASSING_ANNOTATOR.encrypt();
    ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(new CipherOutputStream(baos, sym)));
    oos.writeLong(System.currentTimeMillis());
    oos.writeObject(caw.getConsoleAnnotator());
    oos.close();
    StaplerResponse rsp = Stapler.getCurrentResponse();
    if(rsp != null) {
        rsp.setHeader("X-ConsoleAnnotator", new String(Base64.encode(baos.toByteArray())));
    }
    return r;
}
 
开发者ID:fabric8io,项目名称:fabric8-jenkins-workflow-steps,代码行数:16,代码来源:AnnotatedLargeText.java

示例12: exportPEM

import com.trilead.ssh2.crypto.Base64; //导入依赖的package包/类
public static String exportPEM(PrivateKey key, String secret) throws NoSuchAlgorithmException, InvalidParameterSpecException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, InvalidKeySpecException, IllegalBlockSizeException, IOException {
	StringBuilder sb = new StringBuilder();

	byte[] data = key.getEncoded();

	sb.append(PKCS8_START);
	sb.append('\n');

	if (secret != null) {
		byte[] salt = new byte[8];
		SecureRandom random = new SecureRandom();
		random.nextBytes(salt);

		PBEParameterSpec defParams = new PBEParameterSpec(salt, 1);
		AlgorithmParameters params = AlgorithmParameters.getInstance(key.getAlgorithm());

		params.init(defParams);

		PBEKeySpec pbeSpec = new PBEKeySpec(secret.toCharArray());

		SecretKeyFactory keyFact = SecretKeyFactory.getInstance(key.getAlgorithm());
		Cipher cipher = Cipher.getInstance(key.getAlgorithm());
		cipher.init(Cipher.WRAP_MODE, keyFact.generateSecret(pbeSpec), params);

		byte[] wrappedKey = cipher.wrap(key);

		EncryptedPrivateKeyInfo pinfo = new EncryptedPrivateKeyInfo(params, wrappedKey);

		data = pinfo.getEncoded();

		sb.append("Proc-Type: 4,ENCRYPTED\n");
		sb.append("DEK-Info: DES-EDE3-CBC,");
		sb.append(encodeHex(salt));
		sb.append("\n\n");
	}

	int i = sb.length();
	sb.append(Base64.encode(data));
	for (i += 63; i < sb.length(); i += 64) {
		sb.insert(i, "\n");
	}

	sb.append('\n');
	sb.append(PKCS8_END);
	sb.append('\n');

	return sb.toString();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:49,代码来源:PubkeyUtils.java

示例13: addHostkeyToFile

import com.trilead.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("ISO-8859-1"));
	raf.close();
}
 
开发者ID:dragonlinux,项目名称:connectbot,代码行数:53,代码来源:KnownHosts.java

示例14: createHashedHostname

import com.trilead.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:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:KnownHosts.java

示例15: addHostkeyToFile

import com.trilead.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("ISO-8859-1"));
	raf.close();
}
 
开发者ID:jianlinwei,项目名称:sshtunnel,代码行数:57,代码来源:KnownHosts.java


注:本文中的com.trilead.ssh2.crypto.Base64类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。