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