本文整理匯總了Java中javax.crypto.interfaces.DHPublicKey.getParams方法的典型用法代碼示例。如果您正苦於以下問題:Java DHPublicKey.getParams方法的具體用法?Java DHPublicKey.getParams怎麽用?Java DHPublicKey.getParams使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.crypto.interfaces.DHPublicKey
的用法示例。
在下文中一共展示了DHPublicKey.getParams方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: engineDoPhase
import javax.crypto.interfaces.DHPublicKey; //導入方法依賴的package包/類
protected Key engineDoPhase(
Key key,
boolean lastPhase)
throws InvalidKeyException, IllegalStateException
{
if (x == null)
{
throw new IllegalStateException("Diffie-Hellman not initialised.");
}
if (!(key instanceof DHPublicKey))
{
throw new InvalidKeyException("DHKeyAgreement doPhase requires DHPublicKey");
}
DHPublicKey pubKey = (DHPublicKey)key;
if (!pubKey.getParams().getG().equals(g) || !pubKey.getParams().getP().equals(p))
{
throw new InvalidKeyException("DHPublicKey not for this KeyAgreement!");
}
if (lastPhase)
{
result = ((DHPublicKey)key).getY().modPow(x, p);
return null;
}
else
{
result = ((DHPublicKey)key).getY().modPow(x, p);
}
return new BCDHPublicKey(result, pubKey.getParams());
}
示例2: initKey
import javax.crypto.interfaces.DHPublicKey; //導入方法依賴的package包/類
/**
* 乙方根據甲方公鑰初始化並返回密鑰對
*/
public static Map<String, Object> initKey(byte[] key) throws Exception{
//將甲方公鑰從字節數組轉換為publicKey
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(key);
//實例化密鑰工廠
KeyFactory keyFactory = KeyFactory.getInstance("DH");
//產生甲方公鑰pubKey
DHPublicKey dhPublicKey = (DHPublicKey) keyFactory.generatePublic(keySpec);
//剖析甲方公鑰,得到其參數
DHParameterSpec dhParameterSpec = dhPublicKey.getParams();
//實例化密鑰對生成器
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("DH");
//用甲方公鑰初始化密鑰對生成器
keyPairGenerator.initialize(dhParameterSpec);
//產生密鑰對
KeyPair keyPair = keyPairGenerator.generateKeyPair();
//得到乙方公鑰
DHPublicKey publicKey = (DHPublicKey) keyPair.getPublic();
//得到乙方私鑰
DHPrivateKey privateKey = (DHPrivateKey) keyPair.getPrivate();
//將公鑰和私鑰封裝到Map中,方便以後使用
Map<String, Object> keyMap = new HashMap<String, Object>();
keyMap.put(PUBLIC_KEY, publicKey);
keyMap.put(PRIVATE_KEY, privateKey);
return keyMap;
}
示例3: getDHPublicKeySpec
import javax.crypto.interfaces.DHPublicKey; //導入方法依賴的package包/類
static DHPublicKeySpec getDHPublicKeySpec(PublicKey key) {
if (key instanceof DHPublicKey) {
DHPublicKey dhKey = (DHPublicKey)key;
DHParameterSpec params = dhKey.getParams();
return new DHPublicKeySpec(dhKey.getY(),
params.getP(), params.getG());
}
try {
KeyFactory factory = JsseJce.getKeyFactory("DH");
return factory.getKeySpec(key, DHPublicKeySpec.class);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例4: validateDHPublicKey
import javax.crypto.interfaces.DHPublicKey; //導入方法依賴的package包/類
/**
* Returns whether the Diffie-Hellman public key is valid or not.
*
* Per RFC 2631 and NIST SP800-56A, the following algorithm is used to
* validate Diffie-Hellman public keys:
* 1. Verify that y lies within the interval [2,p-1]. If it does not,
* the key is invalid.
* 2. Compute y^q mod p. If the result == 1, the key is valid.
* Otherwise the key is invalid.
*/
private static void validateDHPublicKey(DHPublicKey publicKey)
throws InvalidKeyException {
DHParameterSpec paramSpec = publicKey.getParams();
BigInteger p = paramSpec.getP();
BigInteger g = paramSpec.getG();
BigInteger y = publicKey.getY();
validateDHPublicKey(p, g, y);
}
示例5: getDHPublicKeySpec
import javax.crypto.interfaces.DHPublicKey; //導入方法依賴的package包/類
static DHPublicKeySpec getDHPublicKeySpec(PublicKey key) {
if (key instanceof DHPublicKey) {
DHPublicKey dhKey = (DHPublicKey)key;
DHParameterSpec params = dhKey.getParams();
return new DHPublicKeySpec(dhKey.getY(),
params.getP(), params.getG());
}
try {
KeyFactory factory = JsseJce.getKeyFactory("DiffieHellman");
return factory.getKeySpec(key, DHPublicKeySpec.class);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例6: createKeys
import javax.crypto.interfaces.DHPublicKey; //導入方法依賴的package包/類
/**
* Create a set of public/private keys using ValueLinks defined parameters
* @return KeyPair object containing both public and private keys
* @throws NoSuchAlgorithmException
* @throws InvalidAlgorithmParameterException
*/
public KeyPair createKeys() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeySpecException {
// initialize the parameter spec
DHPublicKey publicKey = (DHPublicKey) this.getValueLinkPublicKey();
DHParameterSpec dhParamSpec = publicKey.getParams();
//Debug.logInfo(dhParamSpec.getP().toString() + " / " + dhParamSpec.getG().toString(), module);
// create the public/private key pair using parameters defined by valuelink
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DH");
keyGen.initialize(dhParamSpec);
KeyPair keyPair = keyGen.generateKeyPair();
return keyPair;
}
示例7: engineDoPhase
import javax.crypto.interfaces.DHPublicKey; //導入方法依賴的package包/類
protected Key engineDoPhase(Key incoming, boolean lastPhase)
throws InvalidKeyException
{
if (key == null)
throw new IllegalStateException("Not initialized");
if (last_phase_done)
throw new IllegalStateException("Last phase already done");
if (! (incoming instanceof DHPublicKey))
throw new InvalidKeyException("Key MUST be a DHPublicKey");
DHPublicKey pub = (DHPublicKey) incoming;
DHParameterSpec s1 = key.getParams();
DHParameterSpec s2 = pub.getParams();
if (! s1.getG().equals(s2.getG()) || ! s1.getP().equals(s2.getP()))
throw new InvalidKeyException("Incompatible key");
if (! lastPhase)
throw new IllegalArgumentException(
"This key-agreement MUST be concluded in one step only");
BigInteger resultBI = pub.getY().modPow(key.getX(), s1.getP());
result = resultBI.toByteArray();
if (result[0] == 0x00)
{
byte[] buf = new byte[result.length - 1];
System.arraycopy(result, 1, buf, 0, buf.length);
result = buf;
}
last_phase_done = true;
return null;
}
示例8: getDHPublicKeySpec
import javax.crypto.interfaces.DHPublicKey; //導入方法依賴的package包/類
static DHPublicKeySpec getDHPublicKeySpec(PublicKey key) {
if (key instanceof DHPublicKey) {
DHPublicKey dhKey = (DHPublicKey)key;
DHParameterSpec params = dhKey.getParams();
return new DHPublicKeySpec(dhKey.getY(), params.getP(), params.getG());
}
try {
KeyFactory factory = JsseJce.getKeyFactory("DH");
return factory.getKeySpec(key, DHPublicKeySpec.class);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例9: engineDoPhase
import javax.crypto.interfaces.DHPublicKey; //導入方法依賴的package包/類
protected Key engineDoPhase(
Key key,
boolean lastPhase)
throws InvalidKeyException, IllegalStateException
{
if (x == null)
{
throw new IllegalStateException("Diffie-Hellman not initialised.");
}
if (!(key instanceof DHPublicKey))
{
throw new InvalidKeyException("DHKeyAgreement doPhase requires DHPublicKey");
}
DHPublicKey pubKey = (DHPublicKey)key;
if (!pubKey.getParams().getG().equals(g) || !pubKey.getParams().getP().equals(p))
{
throw new InvalidKeyException("DHPublicKey not for this KeyAgreement!");
}
if (lastPhase)
{
result = ((DHPublicKey)key).getY().modPow(x, p);
return null;
}
else
{
result = ((DHPublicKey)key).getY().modPow(x, p);
}
return new JCEDHPublicKey(result, pubKey.getParams());
}
示例10: getDHPublicKeySpec
import javax.crypto.interfaces.DHPublicKey; //導入方法依賴的package包/類
static DHPublicKeySpec getDHPublicKeySpec(PublicKey key) {
if (key instanceof DHPublicKey) {
DHPublicKey dhKey = (DHPublicKey)key;
DHParameterSpec params = dhKey.getParams();
return new DHPublicKeySpec(dhKey.getY(), params.getP(), params.getG());
}
try {
KeyFactory factory = JsseJce.getKeyFactory("DH");
return (DHPublicKeySpec)factory.getKeySpec
(key, DHPublicKeySpec.class);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例11: JCEDHPublicKey
import javax.crypto.interfaces.DHPublicKey; //導入方法依賴的package包/類
JCEDHPublicKey(
DHPublicKey key)
{
this.y = key.getY();
this.dhSpec = key.getParams();
}
示例12: BCDHPublicKey
import javax.crypto.interfaces.DHPublicKey; //導入方法依賴的package包/類
BCDHPublicKey(
DHPublicKey key)
{
this.y = key.getY();
this.dhSpec = key.getParams();
}