java tls 实例_Java TlsMasterSecretParameterSpec类代码示例

import sun.security.internal.spec.TlsMasterSecretParameterSpec; //导入依赖的package包/类

@SuppressWarnings("deprecation")

protected void engineInit(AlgorithmParameterSpec params,

SecureRandom random) throws InvalidAlgorithmParameterException {

if (params instanceof TlsMasterSecretParameterSpec == false) {

throw new InvalidAlgorithmParameterException(MSG);

}

TlsMasterSecretParameterSpec spec = (TlsMasterSecretParameterSpec)params;

int version = (spec.getMajorVersion() << 8) | spec.getMinorVersion();

if ((version == 0x0300 && !supportSSLv3) || (version < 0x0300) ||

(version > 0x0302)) {

throw new InvalidAlgorithmParameterException

("Only" + (supportSSLv3? " SSL 3.0,": "") +

" TLS 1.0, and TLS 1.1 are supported (0x" +

Integer.toHexString(version) + ")");

}

SecretKey key = spec.getPremasterSecret();

// algorithm should be either TlsRsaPremasterSecret or TlsPremasterSecret,

// but we omit the check

try {

p11Key = P11SecretKeyFactory.convertKey(token, key, null);

} catch (InvalidKeyException e) {

throw new InvalidAlgorithmParameterException("init() failed", e);

}

this.spec = spec;

if (p11Key.getAlgorithm().equals("TlsRsaPremasterSecret")) {

mechanism = (version == 0x0300) ? CKM_SSL3_MASTER_KEY_DERIVE

: CKM_TLS_MASTER_KEY_DERIVE;

ckVersion = new CK_VERSION(0, 0);

} else {

// Note: we use DH for all non-RSA premaster secrets. That includes

// Kerberos. That should not be a problem because master secret

// calculation is always a straightforward application of the

// TLS PRF (or the SSL equivalent).

// The only thing special about RSA master secret calculation is

// that it extracts the version numbers from the premaster secret.

mechanism = (version == 0x0300) ? CKM_SSL3_MASTER_KEY_DERIVE_DH

: CKM_TLS_MASTER_KEY_DERIVE_DH;

ckVersion = null;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值