Package java.security.interfaces

Examples of java.security.interfaces.DSAPublicKey


            abstractOutputProcessor.createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_Exponent, false, null);
            abstractOutputProcessor.createCharactersAndOutputAsEvent(outputProcessorChain, new Base64(76, new byte[]{'\n'}).encodeToString(rsaPublicKey.getPublicExponent().toByteArray()));
            abstractOutputProcessor.createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_Exponent);
            abstractOutputProcessor.createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_RSAKeyValue);
        } else if ("DSA".equals(algorithm)) {
            DSAPublicKey dsaPublicKey = (DSAPublicKey) publicKey;
            BigInteger j = dsaPublicKey.getParams().getP().subtract(BigInteger.ONE).divide(dsaPublicKey.getParams().getQ());
            abstractOutputProcessor.createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_DSAKeyValue, false, null);
            abstractOutputProcessor.createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_P, false, null);
            abstractOutputProcessor.createCharactersAndOutputAsEvent(outputProcessorChain, new Base64(76, new byte[]{'\n'}).encodeToString(dsaPublicKey.getParams().getP().toByteArray()));
            abstractOutputProcessor.createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_P);
            abstractOutputProcessor.createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_Q, false, null);
            abstractOutputProcessor.createCharactersAndOutputAsEvent(outputProcessorChain, new Base64(76, new byte[]{'\n'}).encodeToString(dsaPublicKey.getParams().getQ().toByteArray()));
            abstractOutputProcessor.createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_Q);
            abstractOutputProcessor.createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_G, false, null);
            abstractOutputProcessor.createCharactersAndOutputAsEvent(outputProcessorChain, new Base64(76, new byte[]{'\n'}).encodeToString(dsaPublicKey.getParams().getG().toByteArray()));
            abstractOutputProcessor.createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_G);
            abstractOutputProcessor.createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_Y, false, null);
            abstractOutputProcessor.createCharactersAndOutputAsEvent(outputProcessorChain, new Base64(76, new byte[]{'\n'}).encodeToString(dsaPublicKey.getY().toByteArray()));
            abstractOutputProcessor.createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_Y);
            abstractOutputProcessor.createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_J, false, null);
            abstractOutputProcessor.createCharactersAndOutputAsEvent(outputProcessorChain, new Base64(76, new byte[]{'\n'}).encodeToString(j.toByteArray()));
            abstractOutputProcessor.createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_J);
            abstractOutputProcessor.createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_DSAKeyValue);
View Full Code Here


            bcpgKey = new RSAPublicBCPGKey(rK.getModulus(), rK.getPublicExponent());
        }
        else if (pubKey instanceof DSAPublicKey)
        {
            DSAPublicKey    dK = (DSAPublicKey)pubKey;
            DSAParams       dP = dK.getParams();

            bcpgKey = new DSAPublicBCPGKey(dP.getP(), dP.getQ(), dP.getG(), dK.getY());
        }
        else if (pubKey instanceof ElGamalPublicKey)
        {
            ElGamalPublicKey        eK = (ElGamalPublicKey)pubKey;
            ElGamalParameterSpec    eS = eK.getParameters();
View Full Code Here

        PublicKey pubKey = cert.getPublicKey();
        if (!(pubKey instanceof DSAPublicKey))
        {
            return pubKey;
        }
        DSAPublicKey dsaPubKey = (DSAPublicKey) pubKey;
        if (dsaPubKey.getParams() != null)
        {
            return dsaPubKey;
        }
        for (int i = index + 1; i < certs.size(); i++)
        {
            X509Certificate parentCert = (X509Certificate)certs.get(i);
            pubKey = parentCert.getPublicKey();
            if (!(pubKey instanceof DSAPublicKey))
            {
                throw new CertPathValidatorException(
                    "DSA parameters cannot be inherited from previous certificate.");
            }
            DSAPublicKey prevDSAPubKey = (DSAPublicKey) pubKey;
            if (prevDSAPubKey.getParams() == null)
            {
                continue;
            }
            DSAParams dsaParams = prevDSAPubKey.getParams();
            DSAPublicKeySpec dsaPubKeySpec = new DSAPublicKeySpec(
                dsaPubKey.getY(), dsaParams.getP(), dsaParams.getQ(), dsaParams.getG());
            try
            {
                KeyFactory keyFactory = KeyFactory.getInstance("DSA", "BC");
View Full Code Here

                //
                // key encoding test - BC decoding Sun keys
                //
                KeyFactory          f = KeyFactory.getInstance("DSA", "BC");
                X509EncodedKeySpec  x509s = new X509EncodedKeySpec(vKey.getEncoded());
                DSAPublicKey        k1 = (DSAPublicKey)f.generatePublic(x509s);

                if (!k1.getY().equals(((DSAPublicKey)vKey).getY()))
                {
                    return new SimpleTestResult(false, this.getName() + ": public number not decoded properly");
                }

                if (!k1.getParams().getG().equals(((DSAPublicKey)vKey).getParams().getG()))
                {
                    return new SimpleTestResult(false, this.getName() + ": public generator not decoded properly");
                }

                if (!k1.getParams().getP().equals(((DSAPublicKey)vKey).getParams().getP()))
                {
                    return new SimpleTestResult(false, this.getName() + ": public p value not decoded properly");
                }

                if (!k1.getParams().getQ().equals(((DSAPublicKey)vKey).getParams().getQ()))
                {
                    return new SimpleTestResult(false, this.getName() + ": public q value not decoded properly");
                }
               
                PKCS8EncodedKeySpec  pkcs8 = new PKCS8EncodedKeySpec(sKey.getEncoded());
                DSAPrivateKey        k2 = (DSAPrivateKey)f.generatePrivate(pkcs8);

                if (!k2.getX().equals(((DSAPrivateKey)sKey).getX()))
                {
                    return new SimpleTestResult(false, this.getName() + ": private number not decoded properly");
                }

                if (!k2.getParams().getG().equals(((DSAPrivateKey)sKey).getParams().getG()))
                {
                    return new SimpleTestResult(false, this.getName() + ": private generator not decoded properly");
                }

                if (!k2.getParams().getP().equals(((DSAPrivateKey)sKey).getParams().getP()))
                {
                    return new SimpleTestResult(false, this.getName() + ": private p value not decoded properly");
                }

                if (!k2.getParams().getQ().equals(((DSAPrivateKey)sKey).getParams().getQ()))
                {
                    return new SimpleTestResult(false, this.getName() + ": private q value not decoded properly");
                }
               
                //
                // key decoding test - SUN decoding BC keys
                //
                f = KeyFactory.getInstance("DSA", "SUN");
                x509s = new X509EncodedKeySpec(k1.getEncoded());

                vKey = (DSAPublicKey)f.generatePublic(x509s);

                if (!k1.getY().equals(((DSAPublicKey)vKey).getY()))
                {
                    return new SimpleTestResult(false, this.getName() + ": public number not decoded properly");
                }

                if (!k1.getParams().getG().equals(((DSAPublicKey)vKey).getParams().getG()))
                {
                    return new SimpleTestResult(false, this.getName() + ": public generator not decoded properly");
                }

                if (!k1.getParams().getP().equals(((DSAPublicKey)vKey).getParams().getP()))
                {
                    return new SimpleTestResult(false, this.getName() + ": public p value not decoded properly");
                }

                if (!k1.getParams().getQ().equals(((DSAPublicKey)vKey).getParams().getQ()))
                {
                    return new SimpleTestResult(false, this.getName() + ": public q value not decoded properly");
                }

                pkcs8 = new PKCS8EncodedKeySpec(k2.getEncoded());
View Full Code Here

        if (!(o instanceof DSAPublicKey))
        {
            return false;
        }
       
        DSAPublicKey other = (DSAPublicKey)o;
       
        return this.getY().equals(other.getY())
            && this.getParams().getG().equals(other.getParams().getG())
            && this.getParams().getP().equals(other.getParams().getP())
            && this.getParams().getQ().equals(other.getParams().getQ());
    }
View Full Code Here

        PublicKey    key)
        throws InvalidKeyException
    {
        if (key instanceof DSAPublicKey)
        {
            DSAPublicKey    k = (DSAPublicKey)key;

            return new DSAPublicKeyParameters(k.getY(),
                new DSAParameters(k.getParams().getP(), k.getParams().getQ(), k.getParams().getG()));
        }

        throw new InvalidKeyException("can't identify DSA public key: " + key.getClass().getName());
    }
View Full Code Here

  if (key == null) {
      throw new NullPointerException("key cannot be null");
  }
  this.publicKey = key;
  if (key instanceof DSAPublicKey) {
      DSAPublicKey dkey = (DSAPublicKey) key;
      DSAParams params = dkey.getParams();
      p = new DOMCryptoBinary(params.getP());
      q = new DOMCryptoBinary(params.getQ());
      g = new DOMCryptoBinary(params.getG());
      y = new DOMCryptoBinary(dkey.getY());
  } else if (key instanceof RSAPublicKey) {
      RSAPublicKey rkey = (RSAPublicKey) key;
      exponent = new DOMCryptoBinary(rkey.getPublicExponent());
      modulus = new DOMCryptoBinary(rkey.getModulus());
  } else {
View Full Code Here

        return kp;
    }

    protected static boolean areKeyEquals(PublicKey k1, PublicKey k2) {
        if (k1 instanceof DSAPublicKey && k2 instanceof DSAPublicKey) {
            DSAPublicKey d1 = (DSAPublicKey) k1;
            DSAPublicKey d2 = (DSAPublicKey) k2;
            DSAParams p1 = d1.getParams();
            DSAParams p2 = d2.getParams();
            return d1.getY().equals(d2.getY())
                        && p1.getG().equals(p2.getG())
                        && p1.getP().equals(p2.getP())
                        && p1.getQ().equals(p2.getQ());
        } else if (k1 instanceof RSAPublicKey && k2 instanceof RSAPublicKey) {
            RSAPublicKey r1 = (RSAPublicKey) k1;
View Full Code Here

     * if KeySpec argument contains incorrect ASN.1 syntax
     */
    public final void testGeneratePublicKeySpec04() throws Exception {

        X509EncodedKeySpec ks;
        DSAPublicKey pubKey;

        final BigInteger y = publicY;
        final BigInteger p = publicP;
        final BigInteger q = publicQ;
        final BigInteger g = publicG;

        final byte enc1[] = new byte[20];
        System.arraycopy(publicEncoding, 0, enc1, 0, 20);
        final byte[] enc2 = enc1;

        pubKey = new DSAPublicKey () {

                  public BigInteger getY() { return y; }
                  public DSAParams getParams() {
                      return  (DSAParams)(new DSAParameterSpec(p, q, g));
                  }
View Full Code Here

     * whose algorithm is neither null nor "DSA".
     */
    public final void testGeneratePublicKeySpec05() throws Exception {

        X509EncodedKeySpec ks;
        DSAPublicKey pubKey;

        final BigInteger y = publicY;
        final BigInteger p = publicP;
        final BigInteger q = publicQ;
        final BigInteger g = publicG;

        final byte enc1[] = new byte[publicEncoding.length];
        System.arraycopy(publicEncoding, 0, enc1, 0, publicEncoding.length);
        enc1[13] = 0;
        final byte[] enc2 = enc1;

        pubKey = new DSAPublicKey () {

                  public BigInteger getY() { return y; }
                  public DSAParams getParams() {
                      return  (DSAParams)(new DSAParameterSpec(p, q, g));
                  }
                  public String getAlgorithm() { return "DSA"; }
                  public byte[] getEncoded()   { return enc2; }
                  public String getFormat()    { return "X.509"; }
              };

        ks = kf.getKeySpec(pubKey, X509EncodedKeySpec.class);
        pubKey = (DSAPublicKey) kf.generatePublic((KeySpec)ks);

        String alg = pubKey.getAlgorithm();
        assertNotNull(alg);
        assertFalse(alg.equals("DSA"));
    }
View Full Code Here

TOP

Related Classes of java.security.interfaces.DSAPublicKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.