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


Java IESWithCipherParameters類代碼示例

本文整理匯總了Java中org.spongycastle.crypto.params.IESWithCipherParameters的典型用法代碼示例。如果您正苦於以下問題:Java IESWithCipherParameters類的具體用法?Java IESWithCipherParameters怎麽用?Java IESWithCipherParameters使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


IESWithCipherParameters類屬於org.spongycastle.crypto.params包,在下文中一共展示了IESWithCipherParameters類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getCipherParameters

import org.spongycastle.crypto.params.IESWithCipherParameters; //導入依賴的package包/類
private CipherParameters getCipherParameters() {
	return new IESWithCipherParameters(null, null, MAC_KEY_BITS,
			CIPHER_KEY_BITS);
}
 
開發者ID:rafjordao,項目名稱:Nird2,代碼行數:5,代碼來源:MessageEncrypter.java

示例2: encryptBlock

import org.spongycastle.crypto.params.IESWithCipherParameters; //導入依賴的package包/類
private byte[] encryptBlock(byte[] in, int inOff, int inLen) throws InvalidCipherTextException {
    byte[] C = null, K = null, K1 = null, K2 = null;
    int len;

    if (cipher == null) {
        // Streaming mode.
        K1 = new byte[inLen];
        K2 = new byte[param.getMacKeySize() / 8];
        K = new byte[K1.length + K2.length];

        kdf.generateBytes(K, 0, K.length);

        if (V.length != 0) {
            System.arraycopy(K, 0, K2, 0, K2.length);
            System.arraycopy(K, K2.length, K1, 0, K1.length);
        } else {
            System.arraycopy(K, 0, K1, 0, K1.length);
            System.arraycopy(K, inLen, K2, 0, K2.length);
        }

        C = new byte[inLen];

        for (int i = 0; i != inLen; i++) {
            C[i] = (byte) (in[inOff + i] ^ K1[i]);
        }
        len = inLen;
    } else {
        // Block cipher mode.
        K1 = new byte[((IESWithCipherParameters) param).getCipherKeySize() / 8];
        K2 = new byte[param.getMacKeySize() / 8];
        K = new byte[K1.length + K2.length];

        kdf.generateBytes(K, 0, K.length);
        System.arraycopy(K, 0, K1, 0, K1.length);
        System.arraycopy(K, K1.length, K2, 0, K2.length);

        // If iv provided use it to initialise the cipher
        if (IV != null) {
            cipher.init(true, new ParametersWithIV(new KeyParameter(K1), IV));
        } else {
            cipher.init(true, new KeyParameter(K1));
        }

        C = new byte[cipher.getOutputSize(inLen)];
        len = cipher.processBytes(in, inOff, inLen, C, 0);
        len += cipher.doFinal(C, len);
    }

    // Convert the length of the encoding vector into a byte array.
    byte[] P2 = param.getEncodingV();
    byte[] L2 = new byte[4];
    if (V.length != 0 && P2 != null) {
        Pack.intToBigEndian(P2.length * 8, L2, 0);
    }

    // Apply the MAC.
    byte[] T = new byte[mac.getMacSize()];

    byte[] K2a = new byte[hash.getDigestSize()];
    hash.reset();
    hash.update(K2, 0, K2.length);
    hash.doFinal(K2a, 0);
    mac.init(new KeyParameter(K2a));
    mac.update(IV, 0, IV.length);
    mac.update(C, 0, C.length);
    if (P2 != null) {
        mac.update(P2, 0, P2.length);
    }
    if (V.length != 0) {
        mac.update(L2, 0, L2.length);
    }
    mac.doFinal(T, 0);

    // Output the triple (V,C,T).
    byte[] Output = new byte[V.length + len + T.length];
    System.arraycopy(V, 0, Output, 0, V.length);
    System.arraycopy(C, 0, Output, V.length, len);
    System.arraycopy(T, 0, Output, V.length + len, T.length);
    return Output;
}
 
開發者ID:mudpedal,項目名稱:cgk-tetherj,代碼行數:81,代碼來源:EthereumIESEngine.java


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