本文整理匯總了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");
}
}