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


Java Cipher.init方法代碼示例

本文整理匯總了Java中com.sun.spotx.crypto.Cipher.init方法的典型用法代碼示例。如果您正苦於以下問題:Java Cipher.init方法的具體用法?Java Cipher.init怎麽用?Java Cipher.init使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.sun.spotx.crypto.Cipher的用法示例。


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

示例1: init

import com.sun.spotx.crypto.Cipher; //導入方法依賴的package包/類
/**
 * Chops up a master secret into the client and server MAC secrets, 
 * bulk encryption keys and IVs. Also initializes the Cipher and 
 * MessageDigest objects used in record encoding/decoding. 
 * 
 * @param role role (either CLIENT or SERVER) of this side in the SSL 
 *             negotiation
 * @param clientRand 32-byte random value chosen by the client
 * @param serverRand 32-byte random value chosen by the server
 * @param suite negotiated cipher suite
 * @param masterSecret master secret resulting from the key exchange
 *
 * @exception Exception if the negotiated cipher suite involves an 
 *                      unsupported hash or cipher algorithm
 */
void init(byte role, byte[] clientRand, byte[] serverRand, 
          short suite, byte[] masterSecret) throws Exception {
	
    CipherSuiteData data = new CipherSuiteData(suite, ver);
    data.generateKeys(clientRand, serverRand, masterSecret);

    // depending on role, we choose corresponding MAC secrets 
    // and cipher bulk keys for encoder and decoder
    byte[] encodeSecret;
    byte[] decodeSecret;
    SecretKeySpec decodeCipherKey;
    SecretKeySpec encodeCipherKey;
    if (role == CLIENT) {
        encodeSecret = data.getClientMACSecret();
        decodeSecret = data.getServerMACSecret();
        encodeCipherKey = data.getClientBulkKey();
        decodeCipherKey = data.getServerBulkKey();
    } else {
        encodeSecret = data.getServerMACSecret();
        decodeSecret = data.getClientMACSecret();
        encodeCipherKey = data.getServerBulkKey();
        decodeCipherKey = data.getClientBulkKey();
    }
    
    Cipher encodeCipher = data.getEncodeCipher();
    encodeCipher.init(Cipher.ENCRYPT_MODE, encodeCipherKey);
    Cipher decodeCipher = data.getDecodeCipher();
    decodeCipher.init(Cipher.DECRYPT_MODE, decodeCipherKey);
    
    encoder = new RecordEncoder(data.getEncodeDigest(), encodeSecret,
            data.getPadLength(), encodeCipher, ver);
    decoder = new RecordDecoder(data.getDecodeDigest(), decodeSecret,
            data.getPadLength(), decodeCipher, ver);
}
 
開發者ID:tomatsu,項目名稱:squawk,代碼行數:50,代碼來源:Record.java


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