本文整理汇总了Java中com.sshtools.j2ssh.util.Hash类的典型用法代码示例。如果您正苦于以下问题:Java Hash类的具体用法?Java Hash怎么用?Java Hash使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Hash类属于com.sshtools.j2ssh.util包,在下文中一共展示了Hash类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makePassphraseKey
import com.sshtools.j2ssh.util.Hash; //导入依赖的package包/类
private byte[] makePassphraseKey(String passphrase) {
try {
// Generate the key using the passphrase
Hash md5 = new Hash("MD5");
md5.putBytes(passphrase.getBytes());
byte[] key1 = md5.doFinal();
md5.reset();
md5.putBytes(passphrase.getBytes());
md5.putBytes(key1);
byte[] key2 = md5.doFinal();
byte[] key = new byte[32];
System.arraycopy(key1, 0, key, 0, 16);
System.arraycopy(key2, 0, key, 16, 16);
return key;
} catch (NoSuchAlgorithmException nsae) {
return null;
}
}
示例2: getFingerprint
import com.sshtools.j2ssh.util.Hash; //导入依赖的package包/类
/**
*
*
* @return
*/
public String getFingerprint() {
try {
Hash md5 = new Hash("MD5");
md5.putBytes(getEncoded());
byte[] digest = md5.doFinal();
int bits = getBitLength();
bits = (((bits % 8) != 0) ? (bits += (bits % 8)) : bits);
String ret = String.valueOf(bits);
for (int i = 0; i < digest.length; i++) {
ret += (((i == 0) ? ":" : "") + " " +
Integer.toHexString(digest[i] & 0xFF));
}
return ret;
} catch (NoSuchAlgorithmException nsae) {
return null;
}
}
示例3: makeSshKey
import com.sshtools.j2ssh.util.Hash; //导入依赖的package包/类
private byte[] makeSshKey(char chr) throws IOException {
try {
// Create the first 20 bytes of key data
ByteArrayWriter keydata = new ByteArrayWriter();
byte[] data = new byte[20];
Hash hash = new Hash("SHA");
// Put the dh k value
hash.putBigInteger(k);
// Put in the exchange hash
hash.putBytes(exchangeHash);
// Put in the character
hash.putByte((byte) chr);
// Put the exchange hash in again
hash.putBytes(sessionIdentifier);
// Create the fist 20 bytes
data = hash.doFinal();
keydata.write(data);
// Now do the next 20
hash.reset();
// Put the dh k value in again
hash.putBigInteger(k);
// And the exchange hash
hash.putBytes(exchangeHash);
// Finally the first 20 bytes of data we created
hash.putBytes(data);
data = hash.doFinal();
// Put it all together
keydata.write(data);
// Return it
return keydata.toByteArray();
} catch (NoSuchAlgorithmException nsae) {
sendDisconnect(SshMsgDisconnect.KEY_EXCHANGE_FAILED,
"Application error");
throw new TransportProtocolException("SHA algorithm not supported");
} catch (IOException ioe) {
sendDisconnect(SshMsgDisconnect.KEY_EXCHANGE_FAILED,
"Application error");
throw new TransportProtocolException("Error writing key data");
}
}
示例4: makeSshKey
import com.sshtools.j2ssh.util.Hash; //导入依赖的package包/类
private byte[] makeSshKey(final char chr) throws IOException {
try {
// Create the first 20 bytes of key data
final ByteArrayWriter keydata = new ByteArrayWriter();
byte[] data = new byte[20];
final Hash hash = new Hash("SHA");
// Put the dh k value
hash.putBigInteger(k);
// Put in the exchange hash
hash.putBytes(exchangeHash);
// Put in the character
hash.putByte((byte) chr);
// Put the exchange hash in again
hash.putBytes(sessionIdentifier);
// Create the fist 20 bytes
data = hash.doFinal();
keydata.write(data);
// Now do the next 20
hash.reset();
// Put the dh k value in again
hash.putBigInteger(k);
// And the exchange hash
hash.putBytes(exchangeHash);
// Finally the first 20 bytes of data we created
hash.putBytes(data);
data = hash.doFinal();
// Put it all together
keydata.write(data);
// Return it
return keydata.toByteArray();
} catch (final NoSuchAlgorithmException nsae) {
sendDisconnect(SshMsgDisconnect.KEY_EXCHANGE_FAILED,
"Application error");
throw new TransportProtocolException("SHA algorithm not supported");
} catch (final IOException ioe) {
sendDisconnect(SshMsgDisconnect.KEY_EXCHANGE_FAILED,
"Application error");
throw new TransportProtocolException("Error writing key data");
}
}