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