當前位置: 首頁>>代碼示例>>Java>>正文


Java Hash類代碼示例

本文整理匯總了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;
    }
}
 
開發者ID:UniversityofWarwick,項目名稱:j2ssh-fork,代碼行數:22,代碼來源:SshtoolsPrivateKeyFormat.java

示例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;
    }
}
 
開發者ID:UniversityofWarwick,項目名稱:j2ssh-fork,代碼行數:27,代碼來源:SshPublicKey.java

示例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");
    }
}
 
開發者ID:swift-lang,項目名稱:swift-k,代碼行數:58,代碼來源:TransportProtocolCommon.java

示例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");
    }
}
 
開發者ID:UniversityofWarwick,項目名稱:j2ssh-fork,代碼行數:52,代碼來源:TransportProtocolCommon.java


注:本文中的com.sshtools.j2ssh.util.Hash類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。