类java.security.interfaces.DSAPublicKey源码实例Demo

下面列出了怎么用java.security.interfaces.DSAPublicKey的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: jdk1.8-source-analysis   文件: DSAKeyValue.java
/**
 * Constructor DSAKeyValue
 *
 * @param doc
 * @param key
 * @throws IllegalArgumentException
 */
public DSAKeyValue(Document doc, Key key) throws IllegalArgumentException {
    super(doc);

    XMLUtils.addReturnToElement(this.constructionElement);

    if (key instanceof java.security.interfaces.DSAPublicKey) {
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getP(), Constants._TAG_P);
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getQ(), Constants._TAG_Q);
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getG(), Constants._TAG_G);
        this.addBigIntegerElement(((DSAPublicKey) key).getY(), Constants._TAG_Y);
    } else {
        Object exArgs[] = { Constants._TAG_DSAKEYVALUE, key.getClass().getName() };

        throw new IllegalArgumentException(I18n.translate("KeyValue.IllegalArgument", exArgs));
    }
}
 
源代码2 项目: dragonwell8_jdk   文件: BasicChecker.java
/**
 * Internal method to create a new key with inherited key parameters.
 *
 * @param keyValueKey key from which to obtain key value
 * @param keyParamsKey key from which to obtain key parameters
 * @return new public key having value and parameters
 * @throws CertPathValidatorException if keys are not appropriate types
 * for this operation
 */
static PublicKey makeInheritedParamsKey(PublicKey keyValueKey,
    PublicKey keyParamsKey) throws CertPathValidatorException
{
    if (!(keyValueKey instanceof DSAPublicKey) ||
        !(keyParamsKey instanceof DSAPublicKey))
        throw new CertPathValidatorException("Input key is not " +
                                             "appropriate type for " +
                                             "inheriting parameters");
    DSAParams params = ((DSAPublicKey)keyParamsKey).getParams();
    if (params == null)
        throw new CertPathValidatorException("Key parameters missing");
    try {
        BigInteger y = ((DSAPublicKey)keyValueKey).getY();
        KeyFactory kf = KeyFactory.getInstance("DSA");
        DSAPublicKeySpec ks = new DSAPublicKeySpec(y,
                                                   params.getP(),
                                                   params.getQ(),
                                                   params.getG());
        return kf.generatePublic(ks);
    } catch (GeneralSecurityException e) {
        throw new CertPathValidatorException("Unable to generate key with" +
                                             " inherited parameters: " +
                                             e.getMessage(), e);
    }
}
 
源代码3 项目: dragonwell8_jdk   文件: DSAKeyValue.java
/**
 * Constructor DSAKeyValue
 *
 * @param doc
 * @param key
 * @throws IllegalArgumentException
 */
public DSAKeyValue(Document doc, Key key) throws IllegalArgumentException {
    super(doc);

    XMLUtils.addReturnToElement(this.constructionElement);

    if (key instanceof java.security.interfaces.DSAPublicKey) {
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getP(), Constants._TAG_P);
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getQ(), Constants._TAG_Q);
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getG(), Constants._TAG_G);
        this.addBigIntegerElement(((DSAPublicKey) key).getY(), Constants._TAG_Y);
    } else {
        Object exArgs[] = { Constants._TAG_DSAKEYVALUE, key.getClass().getName() };

        throw new IllegalArgumentException(I18n.translate("KeyValue.IllegalArgument", exArgs));
    }
}
 
源代码4 项目: jdk8u-dev-jdk   文件: DSAKeyValue.java
/**
 * Constructor DSAKeyValue
 *
 * @param doc
 * @param key
 * @throws IllegalArgumentException
 */
public DSAKeyValue(Document doc, Key key) throws IllegalArgumentException {
    super(doc);

    XMLUtils.addReturnToElement(this.constructionElement);

    if (key instanceof java.security.interfaces.DSAPublicKey) {
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getP(), Constants._TAG_P);
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getQ(), Constants._TAG_Q);
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getG(), Constants._TAG_G);
        this.addBigIntegerElement(((DSAPublicKey) key).getY(), Constants._TAG_Y);
    } else {
        Object exArgs[] = { Constants._TAG_DSAKEYVALUE, key.getClass().getName() };

        throw new IllegalArgumentException(I18n.translate("KeyValue.IllegalArgument", exArgs));
    }
}
 
源代码5 项目: freehealth-connector   文件: STSServiceImpl.java
private String processHolderOfKeyCredentials(Credential hokCred, String request) throws TechnicalConnectorException, CertificateEncodingException {
   if (hokCred != null && hokCred.getCertificate() != null) {
      request = StringUtils.replace(request, "${holder.of.key}", new String(Base64.encode(hokCred.getCertificate().getEncoded())));
      PublicKey publicKey = hokCred.getCertificate().getPublicKey();
      if (publicKey instanceof RSAPublicKey) {
         RSAPublicKey rsaPublicKey = (RSAPublicKey)publicKey;
         request = StringUtils.replace(request, "${publickey.rsa.modulus}", new String(Base64.encode(convertTo(rsaPublicKey.getModulus()))));
         request = StringUtils.replace(request, "${publickey.rsa.exponent}", new String(Base64.encode(convertTo(rsaPublicKey.getPublicExponent()))));
         request = StringUtils.replace(request, "<ds:DSAKeyValue><ds:G>${publickey.dsa.g}<ds:G><ds:P>${publickey.dsa.p}</ds:P><ds:Q>${publickey.dsa.q}</ds:Q></ds:DSAKeyValue>", "");
      } else if (publicKey instanceof DSAPublicKey) {
         DSAPublicKey dsaPublicKey = (DSAPublicKey)publicKey;
         request = StringUtils.replace(request, "${publickey.dsa.g}", new String(Base64.encode(convertTo(dsaPublicKey.getParams().getG()))));
         request = StringUtils.replace(request, "${publickey.dsa.p}", new String(Base64.encode(convertTo(dsaPublicKey.getParams().getP()))));
         request = StringUtils.replace(request, "${publickey.dsa.q}", new String(Base64.encode(convertTo(dsaPublicKey.getParams().getQ()))));
         request = StringUtils.replace(request, "<ds:RSAKeyValue><ds:Modulus>${publickey.rsa.modulus}</ds:Modulus><ds:Exponent>${publickey.rsa.exponent}</ds:Exponent></ds:RSAKeyValue>", "");
      } else {
         LOG.info("Unsupported public key: [" + publicKey.getClass().getName() + "+]");
      }
   }

   return request;
}
 
源代码6 项目: freehealth-connector   文件: STSServiceImpl.java
private String processHolderOfKeyCredentials(Credential hokCred, String request) throws TechnicalConnectorException, CertificateEncodingException {
   if (hokCred != null && hokCred.getCertificate() != null) {
      request = StringUtils.replace(request, "${holder.of.key}", new String(Base64.encode(hokCred.getCertificate().getEncoded())));
      PublicKey publicKey = hokCred.getCertificate().getPublicKey();
      if (publicKey instanceof RSAPublicKey) {
         RSAPublicKey rsaPublicKey = (RSAPublicKey)publicKey;
         request = StringUtils.replace(request, "${publickey.rsa.modulus}", new String(Base64.encode(convertTo(rsaPublicKey.getModulus()))));
         request = StringUtils.replace(request, "${publickey.rsa.exponent}", new String(Base64.encode(convertTo(rsaPublicKey.getPublicExponent()))));
         request = StringUtils.replace(request, "<ds:DSAKeyValue><ds:G>${publickey.dsa.g}<ds:G><ds:P>${publickey.dsa.p}</ds:P><ds:Q>${publickey.dsa.q}</ds:Q></ds:DSAKeyValue>", "");
      } else if (publicKey instanceof DSAPublicKey) {
         DSAPublicKey dsaPublicKey = (DSAPublicKey)publicKey;
         request = StringUtils.replace(request, "${publickey.dsa.g}", new String(Base64.encode(convertTo(dsaPublicKey.getParams().getG()))));
         request = StringUtils.replace(request, "${publickey.dsa.p}", new String(Base64.encode(convertTo(dsaPublicKey.getParams().getP()))));
         request = StringUtils.replace(request, "${publickey.dsa.q}", new String(Base64.encode(convertTo(dsaPublicKey.getParams().getQ()))));
         request = StringUtils.replace(request, "<ds:RSAKeyValue><ds:Modulus>${publickey.rsa.modulus}</ds:Modulus><ds:Exponent>${publickey.rsa.exponent}</ds:Exponent></ds:RSAKeyValue>", "");
      } else {
         LOG.info("Unsupported public key: [" + publicKey.getClass().getName() + "+]");
      }
   }

   return request;
}
 
源代码7 项目: openjdk-8   文件: BasicChecker.java
/**
 * Internal method to create a new key with inherited key parameters.
 *
 * @param keyValueKey key from which to obtain key value
 * @param keyParamsKey key from which to obtain key parameters
 * @return new public key having value and parameters
 * @throws CertPathValidatorException if keys are not appropriate types
 * for this operation
 */
static PublicKey makeInheritedParamsKey(PublicKey keyValueKey,
    PublicKey keyParamsKey) throws CertPathValidatorException
{
    if (!(keyValueKey instanceof DSAPublicKey) ||
        !(keyParamsKey instanceof DSAPublicKey))
        throw new CertPathValidatorException("Input key is not " +
                                             "appropriate type for " +
                                             "inheriting parameters");
    DSAParams params = ((DSAPublicKey)keyParamsKey).getParams();
    if (params == null)
        throw new CertPathValidatorException("Key parameters missing");
    try {
        BigInteger y = ((DSAPublicKey)keyValueKey).getY();
        KeyFactory kf = KeyFactory.getInstance("DSA");
        DSAPublicKeySpec ks = new DSAPublicKeySpec(y,
                                                   params.getP(),
                                                   params.getQ(),
                                                   params.getG());
        return kf.generatePublic(ks);
    } catch (GeneralSecurityException e) {
        throw new CertPathValidatorException("Unable to generate key with" +
                                             " inherited parameters: " +
                                             e.getMessage(), e);
    }
}
 
源代码8 项目: xipki   文件: AlgorithmUtil.java
public static AlgorithmIdentifier getSigAlgId(PublicKey pubKey, HashAlgo hashAlgo,
    SignatureAlgoControl algoControl) throws NoSuchAlgorithmException {
  Args.notNull(hashAlgo, "hashAlgo");

  if (pubKey instanceof RSAPublicKey) {
    boolean rsaMgf1 = (algoControl == null) ? false : algoControl.isRsaMgf1();
    return getRSASigAlgId(hashAlgo, rsaMgf1);
  } else if (pubKey instanceof ECPublicKey) {
    boolean dsaPlain = (algoControl == null) ? false : algoControl.isDsaPlain();
    boolean gm =  (algoControl == null) ? false : algoControl.isGm();
    return getECSigAlgId(hashAlgo, dsaPlain, gm);
  } else if (pubKey instanceof DSAPublicKey) {
    return getDSASigAlgId(hashAlgo);
  } else {
    throw new NoSuchAlgorithmException("Unknown public key '" + pubKey.getClass().getName());
  }
}
 
源代码9 项目: jdk8u60   文件: DSAKeyValue.java
/**
 * Constructor DSAKeyValue
 *
 * @param doc
 * @param key
 * @throws IllegalArgumentException
 */
public DSAKeyValue(Document doc, Key key) throws IllegalArgumentException {
    super(doc);

    XMLUtils.addReturnToElement(this.constructionElement);

    if (key instanceof java.security.interfaces.DSAPublicKey) {
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getP(), Constants._TAG_P);
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getQ(), Constants._TAG_Q);
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getG(), Constants._TAG_G);
        this.addBigIntegerElement(((DSAPublicKey) key).getY(), Constants._TAG_Y);
    } else {
        Object exArgs[] = { Constants._TAG_DSAKEYVALUE, key.getClass().getName() };

        throw new IllegalArgumentException(I18n.translate("KeyValue.IllegalArgument", exArgs));
    }
}
 
源代码10 项目: JDKSourceCode1.8   文件: DSAKeyValue.java
/**
 * Constructor DSAKeyValue
 *
 * @param doc
 * @param key
 * @throws IllegalArgumentException
 */
public DSAKeyValue(Document doc, Key key) throws IllegalArgumentException {
    super(doc);

    XMLUtils.addReturnToElement(this.constructionElement);

    if (key instanceof java.security.interfaces.DSAPublicKey) {
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getP(), Constants._TAG_P);
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getQ(), Constants._TAG_Q);
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getG(), Constants._TAG_G);
        this.addBigIntegerElement(((DSAPublicKey) key).getY(), Constants._TAG_Y);
    } else {
        Object exArgs[] = { Constants._TAG_DSAKEYVALUE, key.getClass().getName() };

        throw new IllegalArgumentException(I18n.translate("KeyValue.IllegalArgument", exArgs));
    }
}
 
源代码11 项目: quarkus   文件: DSAKeyUtil.java
public static void main(String[] args) throws Exception {
    Provider provider = Security.getProvider("SUN");
    System.out.println(provider.getInfo());
    for (Provider.Service service : provider.getServices()) {
        System.out.println(service);
    }

    KeyPairGenerator kpg = KeyPairGenerator.getInstance("DSA");
    kpg.initialize(2048);
    System.out.println("DSA.provider: " + kpg.getProvider());
    KeyFactory keyFactory = KeyFactory.getInstance("DSA");
    System.out.println("DSA.provider: " + keyFactory.getProvider());

    KeyPair pair = kpg.genKeyPair();
    DSAPublicKey publicKey = (DSAPublicKey) pair.getPublic();
    byte[] encoded = publicKey.getEncoded();
    X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(encoded);
    DSAPublicKey publicKey1 = (DSAPublicKey) keyFactory.generatePublic(publicKeySpec);
    System.out.printf("keys are equal: %s%n", publicKey1.equals(publicKey));

    String base64 = Base64.getEncoder().encodeToString(encoded);
    System.out.println(base64);
}
 
源代码12 项目: keystore-explorer   文件: DViewPublicKey.java
private void populateDialog() throws CryptoException {
	KeyInfo keyInfo = KeyPairUtil.getKeyInfo(publicKey);

	jtfAlgorithm.setText(keyInfo.getAlgorithm());

	Integer keyLength = keyInfo.getSize();

	if (keyLength != null) {
		jtfKeySize.setText(MessageFormat.format(res.getString("DViewPublicKey.jtfKeySize.text"), "" + keyLength));
	} else {
		jtfKeySize.setText(MessageFormat.format(res.getString("DViewPublicKey.jtfKeySize.text"), "?"));
	}

	jtfFormat.setText(publicKey.getFormat());

	jtaEncoded.setText(new BigInteger(1, publicKey.getEncoded()).toString(16).toUpperCase());
	jtaEncoded.setCaretPosition(0);

	if ((publicKey instanceof RSAPublicKey) || (publicKey instanceof DSAPublicKey)) {
		jbFields.setEnabled(true);
	} else {
		jbFields.setEnabled(false);
	}
}
 
源代码13 项目: xipki   文件: CaEnrollBenchKeyEntry.java
public DSAKeyEntry(int plength) throws Exception {
  if (plength == 1024) {
    init(P_1024, Q_1024, G_1024, Y_1024);
  } else if (plength == 2048) {
    init(P_2048, Q_2048, G_2048, Y_2048);
  } else if (plength == 3072) {
    init(P_3072, Q_3072, G_3072, Y_3072);
  } else {
    if (plength % 1024 != 0) {
      throw new IllegalArgumentException("invalid DSA pLength " + plength);
    }

    int qlength = (plength >= 2048) ? 256 : 160;
    KeyPair kp = KeyUtil.generateDSAKeypair(plength, qlength, new SecureRandom());
    DSAPublicKey pk = (DSAPublicKey) kp.getPublic();

    init(pk.getParams().getP(), pk.getParams().getQ(), pk.getParams().getG(), pk.getY());
  }
}
 
源代码14 项目: openjdk-jdk8u   文件: BasicChecker.java
/**
 * Internal method to create a new key with inherited key parameters.
 *
 * @param keyValueKey key from which to obtain key value
 * @param keyParamsKey key from which to obtain key parameters
 * @return new public key having value and parameters
 * @throws CertPathValidatorException if keys are not appropriate types
 * for this operation
 */
static PublicKey makeInheritedParamsKey(PublicKey keyValueKey,
    PublicKey keyParamsKey) throws CertPathValidatorException
{
    if (!(keyValueKey instanceof DSAPublicKey) ||
        !(keyParamsKey instanceof DSAPublicKey))
        throw new CertPathValidatorException("Input key is not " +
                                             "appropriate type for " +
                                             "inheriting parameters");
    DSAParams params = ((DSAPublicKey)keyParamsKey).getParams();
    if (params == null)
        throw new CertPathValidatorException("Key parameters missing");
    try {
        BigInteger y = ((DSAPublicKey)keyValueKey).getY();
        KeyFactory kf = KeyFactory.getInstance("DSA");
        DSAPublicKeySpec ks = new DSAPublicKeySpec(y,
                                                   params.getP(),
                                                   params.getQ(),
                                                   params.getG());
        return kf.generatePublic(ks);
    } catch (GeneralSecurityException e) {
        throw new CertPathValidatorException("Unable to generate key with" +
                                             " inherited parameters: " +
                                             e.getMessage(), e);
    }
}
 
源代码15 项目: wycheproof   文件: DsaTest.java
/**
 * This is just a test for basic functionality of DSA. The test generates a public and private
 * key, generates a signature and verifies it. This test is slow with some providers, since
 * some providers generate new DSA parameters (p and q) for each new key.
 */
@SlowTest(providers = {ProviderType.BOUNCY_CASTLE, ProviderType.SPONGY_CASTLE})
@SuppressWarnings("InsecureCryptoUsage")
@Test
public void testBasic() throws Exception {
  int keySize = 2048;
  String algorithm = "SHA256WithDSA";
  String message = "Hello";

  byte[] messageBytes = message.getBytes("UTF-8");
  KeyPairGenerator generator = java.security.KeyPairGenerator.getInstance("DSA");
  generator.initialize(keySize);
  KeyPair keyPair = generator.generateKeyPair();
  DSAPublicKey pub = (DSAPublicKey) keyPair.getPublic();
  DSAPrivateKey priv = (DSAPrivateKey) keyPair.getPrivate();
  Signature signer = Signature.getInstance(algorithm);
  Signature verifier = Signature.getInstance(algorithm);
  signer.initSign(priv);
  signer.update(messageBytes);
  byte[] signature = signer.sign();
  verifier.initVerify(pub);
  verifier.update(messageBytes);
  assertTrue(verifier.verify(signature));
}
 
源代码16 项目: dnsjava   文件: DNSSEC.java
private static byte[] fromDSAPublicKey(DSAPublicKey key) {
  DNSOutput out = new DNSOutput();
  BigInteger q = key.getParams().getQ();
  BigInteger p = key.getParams().getP();
  BigInteger g = key.getParams().getG();
  BigInteger y = key.getY();
  int t = (p.toByteArray().length - 64) / 8;

  out.writeU8(t);
  writeBigInteger(out, q);
  writeBigInteger(out, p);
  writePaddedBigInteger(out, g, 8 * t + 64);
  writePaddedBigInteger(out, y, 8 * t + 64);

  return out.toByteArray();
}
 
源代码17 项目: xipki   文件: P11PrivateKey.java
public P11PrivateKey(P11CryptService p11CryptService, P11IdentityId identityId)
    throws P11TokenException {
  this.p11CryptService = Args.notNull(p11CryptService, "p11CryptService");
  this.identityId = Args.notNull(identityId, "identityId");

  this.publicKey = p11CryptService.getIdentity(identityId).getPublicKey();

  if (publicKey instanceof RSAPublicKey) {
    algorithm = "RSA";
    keysize = ((RSAPublicKey) publicKey).getModulus().bitLength();
  } else if (publicKey instanceof DSAPublicKey) {
    algorithm = "DSA";
    keysize = ((DSAPublicKey) publicKey).getParams().getP().bitLength();
  } else if (publicKey instanceof ECPublicKey) {
    algorithm = "EC";
    keysize = ((ECPublicKey) publicKey).getParams().getCurve().getField().getFieldSize();
  } else if (publicKey instanceof EdDSAKey) {
    algorithm = publicKey.getAlgorithm();
    keysize = EdECConstants.getKeyBitSize(EdECConstants.getCurveOid(algorithm));
  } else {
    throw new P11TokenException("unknown public key: " + publicKey);
  }
}
 
源代码18 项目: lams   文件: KeyInfoHelper.java
/**
 * Builds a {@link DSAKeyValue} XMLObject from the Java security DSA public key type.
 * 
 * @param dsaPubKey a native Java {@link DSAPublicKey}
 * @return an {@link DSAKeyValue} XMLObject
 */
public static DSAKeyValue buildDSAKeyValue(DSAPublicKey dsaPubKey) {
    XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory();
    DSAKeyValue dsaKeyValue = (DSAKeyValue) builderFactory
        .getBuilder(DSAKeyValue.DEFAULT_ELEMENT_NAME)
        .buildObject(DSAKeyValue.DEFAULT_ELEMENT_NAME);
    Y y = (Y) builderFactory.getBuilder(Y.DEFAULT_ELEMENT_NAME).buildObject(Y.DEFAULT_ELEMENT_NAME);
    G g = (G) builderFactory.getBuilder(G.DEFAULT_ELEMENT_NAME).buildObject(G.DEFAULT_ELEMENT_NAME);
    P p = (P) builderFactory.getBuilder(P.DEFAULT_ELEMENT_NAME).buildObject(P.DEFAULT_ELEMENT_NAME);
    Q q = (Q) builderFactory.getBuilder(Q.DEFAULT_ELEMENT_NAME).buildObject(Q.DEFAULT_ELEMENT_NAME);
    
    y.setValueBigInt(dsaPubKey.getY());
    dsaKeyValue.setY(y);
    
    g.setValueBigInt(dsaPubKey.getParams().getG());
    dsaKeyValue.setG(g);
    
    p.setValueBigInt(dsaPubKey.getParams().getP());
    dsaKeyValue.setP(p);
    
    q.setValueBigInt(dsaPubKey.getParams().getQ());
    dsaKeyValue.setQ(q);
    
    return dsaKeyValue;
}
 
源代码19 项目: jdk8u_jdk   文件: DSAKeyValue.java
/**
 * Constructor DSAKeyValue
 *
 * @param doc
 * @param key
 * @throws IllegalArgumentException
 */
public DSAKeyValue(Document doc, Key key) throws IllegalArgumentException {
    super(doc);

    XMLUtils.addReturnToElement(this.constructionElement);

    if (key instanceof java.security.interfaces.DSAPublicKey) {
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getP(), Constants._TAG_P);
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getQ(), Constants._TAG_Q);
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getG(), Constants._TAG_G);
        this.addBigIntegerElement(((DSAPublicKey) key).getY(), Constants._TAG_Y);
    } else {
        Object exArgs[] = { Constants._TAG_DSAKEYVALUE, key.getClass().getName() };

        throw new IllegalArgumentException(I18n.translate("KeyValue.IllegalArgument", exArgs));
    }
}
 
源代码20 项目: lams   文件: Encrypter.java
/**
 * Check key encryption parameters for consistency and required values.
 * 
 * @param kekParams the key encryption parameters to check
 * @param allowEmpty if false, a null parameter is treated as an error
 * 
 * @throws EncryptionException thrown if any parameters are missing or have invalid values
 */
protected void checkParams(KeyEncryptionParameters kekParams, boolean allowEmpty) throws EncryptionException {
    if (kekParams == null) {
        if (allowEmpty) {
            return;
        } else {
            log.error("Key encryption parameters are required");
            throw new EncryptionException("Key encryption parameters are required");
        }
    }
    Key key = SecurityHelper.extractEncryptionKey(kekParams.getEncryptionCredential());
    if (key == null) {
        log.error("Key encryption credential and contained key are required");
        throw new EncryptionException("Key encryption credential and contained key are required");
    } else if (key instanceof DSAPublicKey) {
        log.error("Attempt made to use DSA key for encrypted key transport");
        throw new EncryptionException("DSA keys may not be used for encrypted key transport");
    } else if (key instanceof ECPublicKey) {
        log.error("Attempt made to use EC key for encrypted key transport");
        throw new EncryptionException("EC keys may not be used for encrypted key transport");
    } else if (DatatypeHelper.isEmpty(kekParams.getAlgorithm())) {
        log.error("Key encryption algorithm URI is required");
        throw new EncryptionException("Key encryption algorithm URI is required");
    }
}
 
源代码21 项目: protools   文件: ToolDSA.java
/**
 * 生成密钥
 *
 * @return 密钥对象
 *
 * @throws Exception
 */
public static Map<String, Object> initKey() throws NoSuchAlgorithmException {
    // 初始化密钥对儿生成器
    KeyPairGenerator keygen = KeyPairGenerator.getInstance(ALGORITHM);

    // 实例化密钥对儿生成器
    keygen.initialize(KEY_SIZE, new SecureRandom());

    // 实例化密钥对儿
    KeyPair keys = keygen.genKeyPair();

    DSAPublicKey publicKey = (DSAPublicKey) keys.getPublic();

    DSAPrivateKey privateKey = (DSAPrivateKey) keys.getPrivate();

    // 封装密钥
    Map<String, Object> map = Maps.newHashMapWithExpectedSize(2);

    map.put(PUBLIC_KEY, publicKey);
    map.put(PRIVATE_KEY, privateKey);

    return map;
}
 
源代码22 项目: j2objc   文件: BasicChecker.java
/**
 * Internal method to create a new key with inherited key parameters.
 *
 * @param keyValueKey key from which to obtain key value
 * @param keyParamsKey key from which to obtain key parameters
 * @return new public key having value and parameters
 * @throws CertPathValidatorException if keys are not appropriate types
 * for this operation
 */
static PublicKey makeInheritedParamsKey(PublicKey keyValueKey,
    PublicKey keyParamsKey) throws CertPathValidatorException
{
    if (!(keyValueKey instanceof DSAPublicKey) ||
        !(keyParamsKey instanceof DSAPublicKey))
        throw new CertPathValidatorException("Input key is not " +
                                             "appropriate type for " +
                                             "inheriting parameters");
    DSAParams params = ((DSAPublicKey)keyParamsKey).getParams();
    if (params == null)
        throw new CertPathValidatorException("Key parameters missing");
    try {
        BigInteger y = ((DSAPublicKey)keyValueKey).getY();
        KeyFactory kf = KeyFactory.getInstance("DSA");
        DSAPublicKeySpec ks = new DSAPublicKeySpec(y,
                                                   params.getP(),
                                                   params.getQ(),
                                                   params.getG());
        return kf.generatePublic(ks);
    } catch (GeneralSecurityException e) {
        throw new CertPathValidatorException("Unable to generate key with" +
                                             " inherited parameters: " +
                                             e.getMessage(), e);
    }
}
 
源代码23 项目: Bytecoder   文件: BasicChecker.java
/**
 * Internal method to create a new key with inherited key parameters.
 *
 * @param keyValueKey key from which to obtain key value
 * @param keyParamsKey key from which to obtain key parameters
 * @return new public key having value and parameters
 * @throws CertPathValidatorException if keys are not appropriate types
 * for this operation
 */
static PublicKey makeInheritedParamsKey(PublicKey keyValueKey,
    PublicKey keyParamsKey) throws CertPathValidatorException
{
    if (!(keyValueKey instanceof DSAPublicKey) ||
        !(keyParamsKey instanceof DSAPublicKey))
        throw new CertPathValidatorException("Input key is not " +
                                             "appropriate type for " +
                                             "inheriting parameters");
    DSAParams params = ((DSAPublicKey)keyParamsKey).getParams();
    if (params == null)
        throw new CertPathValidatorException("Key parameters missing");
    try {
        BigInteger y = ((DSAPublicKey)keyValueKey).getY();
        KeyFactory kf = KeyFactory.getInstance("DSA");
        DSAPublicKeySpec ks = new DSAPublicKeySpec(y,
                                                   params.getP(),
                                                   params.getQ(),
                                                   params.getG());
        return kf.generatePublic(ks);
    } catch (GeneralSecurityException e) {
        throw new CertPathValidatorException("Unable to generate key with" +
                                             " inherited parameters: " +
                                             e.getMessage(), e);
    }
}
 
源代码24 项目: openjdk-jdk9   文件: DSAKeyValue.java
/**
 * Constructor DSAKeyValue
 *
 * @param doc
 * @param key
 * @throws IllegalArgumentException
 */
public DSAKeyValue(Document doc, Key key) throws IllegalArgumentException {
    super(doc);

    XMLUtils.addReturnToElement(this.constructionElement);

    if (key instanceof java.security.interfaces.DSAPublicKey) {
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getP(), Constants._TAG_P);
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getQ(), Constants._TAG_Q);
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getG(), Constants._TAG_G);
        this.addBigIntegerElement(((DSAPublicKey) key).getY(), Constants._TAG_Y);
    } else {
        Object exArgs[] = { Constants._TAG_DSAKEYVALUE, key.getClass().getName() };

        throw new IllegalArgumentException(I18n.translate("KeyValue.IllegalArgument", exArgs));
    }
}
 
源代码25 项目: jdk8u_jdk   文件: BasicChecker.java
/**
 * Internal method to create a new key with inherited key parameters.
 *
 * @param keyValueKey key from which to obtain key value
 * @param keyParamsKey key from which to obtain key parameters
 * @return new public key having value and parameters
 * @throws CertPathValidatorException if keys are not appropriate types
 * for this operation
 */
static PublicKey makeInheritedParamsKey(PublicKey keyValueKey,
    PublicKey keyParamsKey) throws CertPathValidatorException
{
    if (!(keyValueKey instanceof DSAPublicKey) ||
        !(keyParamsKey instanceof DSAPublicKey))
        throw new CertPathValidatorException("Input key is not " +
                                             "appropriate type for " +
                                             "inheriting parameters");
    DSAParams params = ((DSAPublicKey)keyParamsKey).getParams();
    if (params == null)
        throw new CertPathValidatorException("Key parameters missing");
    try {
        BigInteger y = ((DSAPublicKey)keyValueKey).getY();
        KeyFactory kf = KeyFactory.getInstance("DSA");
        DSAPublicKeySpec ks = new DSAPublicKeySpec(y,
                                                   params.getP(),
                                                   params.getQ(),
                                                   params.getG());
        return kf.generatePublic(ks);
    } catch (GeneralSecurityException e) {
        throw new CertPathValidatorException("Unable to generate key with" +
                                             " inherited parameters: " +
                                             e.getMessage(), e);
    }
}
 
源代码26 项目: jdk8u-jdk   文件: DSAKeyValue.java
/**
 * Constructor DSAKeyValue
 *
 * @param doc
 * @param key
 * @throws IllegalArgumentException
 */
public DSAKeyValue(Document doc, Key key) throws IllegalArgumentException {
    super(doc);

    XMLUtils.addReturnToElement(this.constructionElement);

    if (key instanceof java.security.interfaces.DSAPublicKey) {
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getP(), Constants._TAG_P);
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getQ(), Constants._TAG_Q);
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getG(), Constants._TAG_G);
        this.addBigIntegerElement(((DSAPublicKey) key).getY(), Constants._TAG_Y);
    } else {
        Object exArgs[] = { Constants._TAG_DSAKEYVALUE, key.getClass().getName() };

        throw new IllegalArgumentException(I18n.translate("KeyValue.IllegalArgument", exArgs));
    }
}
 
源代码27 项目: hottub   文件: BasicChecker.java
/**
 * Internal method to create a new key with inherited key parameters.
 *
 * @param keyValueKey key from which to obtain key value
 * @param keyParamsKey key from which to obtain key parameters
 * @return new public key having value and parameters
 * @throws CertPathValidatorException if keys are not appropriate types
 * for this operation
 */
static PublicKey makeInheritedParamsKey(PublicKey keyValueKey,
    PublicKey keyParamsKey) throws CertPathValidatorException
{
    if (!(keyValueKey instanceof DSAPublicKey) ||
        !(keyParamsKey instanceof DSAPublicKey))
        throw new CertPathValidatorException("Input key is not " +
                                             "appropriate type for " +
                                             "inheriting parameters");
    DSAParams params = ((DSAPublicKey)keyParamsKey).getParams();
    if (params == null)
        throw new CertPathValidatorException("Key parameters missing");
    try {
        BigInteger y = ((DSAPublicKey)keyValueKey).getY();
        KeyFactory kf = KeyFactory.getInstance("DSA");
        DSAPublicKeySpec ks = new DSAPublicKeySpec(y,
                                                   params.getP(),
                                                   params.getQ(),
                                                   params.getG());
        return kf.generatePublic(ks);
    } catch (GeneralSecurityException e) {
        throw new CertPathValidatorException("Unable to generate key with" +
                                             " inherited parameters: " +
                                             e.getMessage(), e);
    }
}
 
源代码28 项目: hottub   文件: DSAKeyValue.java
/**
 * Constructor DSAKeyValue
 *
 * @param doc
 * @param key
 * @throws IllegalArgumentException
 */
public DSAKeyValue(Document doc, Key key) throws IllegalArgumentException {
    super(doc);

    XMLUtils.addReturnToElement(this.constructionElement);

    if (key instanceof java.security.interfaces.DSAPublicKey) {
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getP(), Constants._TAG_P);
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getQ(), Constants._TAG_Q);
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getG(), Constants._TAG_G);
        this.addBigIntegerElement(((DSAPublicKey) key).getY(), Constants._TAG_Y);
    } else {
        Object exArgs[] = { Constants._TAG_DSAKEYVALUE, key.getClass().getName() };

        throw new IllegalArgumentException(I18n.translate("KeyValue.IllegalArgument", exArgs));
    }
}
 
源代码29 项目: openjdk-8-source   文件: BasicChecker.java
/**
 * Internal method to create a new key with inherited key parameters.
 *
 * @param keyValueKey key from which to obtain key value
 * @param keyParamsKey key from which to obtain key parameters
 * @return new public key having value and parameters
 * @throws CertPathValidatorException if keys are not appropriate types
 * for this operation
 */
static PublicKey makeInheritedParamsKey(PublicKey keyValueKey,
    PublicKey keyParamsKey) throws CertPathValidatorException
{
    if (!(keyValueKey instanceof DSAPublicKey) ||
        !(keyParamsKey instanceof DSAPublicKey))
        throw new CertPathValidatorException("Input key is not " +
                                             "appropriate type for " +
                                             "inheriting parameters");
    DSAParams params = ((DSAPublicKey)keyParamsKey).getParams();
    if (params == null)
        throw new CertPathValidatorException("Key parameters missing");
    try {
        BigInteger y = ((DSAPublicKey)keyValueKey).getY();
        KeyFactory kf = KeyFactory.getInstance("DSA");
        DSAPublicKeySpec ks = new DSAPublicKeySpec(y,
                                                   params.getP(),
                                                   params.getQ(),
                                                   params.getG());
        return kf.generatePublic(ks);
    } catch (GeneralSecurityException e) {
        throw new CertPathValidatorException("Unable to generate key with" +
                                             " inherited parameters: " +
                                             e.getMessage(), e);
    }
}
 
源代码30 项目: openjdk-8-source   文件: DSAKeyValue.java
/**
 * Constructor DSAKeyValue
 *
 * @param doc
 * @param key
 * @throws IllegalArgumentException
 */
public DSAKeyValue(Document doc, Key key) throws IllegalArgumentException {
    super(doc);

    XMLUtils.addReturnToElement(this.constructionElement);

    if (key instanceof java.security.interfaces.DSAPublicKey) {
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getP(), Constants._TAG_P);
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getQ(), Constants._TAG_Q);
        this.addBigIntegerElement(((DSAPublicKey) key).getParams().getG(), Constants._TAG_G);
        this.addBigIntegerElement(((DSAPublicKey) key).getY(), Constants._TAG_Y);
    } else {
        Object exArgs[] = { Constants._TAG_DSAKEYVALUE, key.getClass().getName() };

        throw new IllegalArgumentException(I18n.translate("KeyValue.IllegalArgument", exArgs));
    }
}
 
 类所在包
 同包方法