Package java.security.interfaces

Examples of java.security.interfaces.DSAPublicKey


    kp = kpg.generate();

    byte[] pk;

    DSAPublicKey pubK = (DSAPublicKey) kp.getPublic();
    DSAPrivateKey secK = (DSAPrivateKey) kp.getPrivate();

    pk = ((DSSPrivateKey) secK).getEncoded(IKeyPairCodec.PKCS8_FORMAT);
    PrivateKey newSecK = new DSSKeyPairPKCS8Codec().decodePrivateKey(pk);
    harness.check(secK.equals(newSecK),
                  "DSS private key ASN.1 encoder/decoder test");

    pk = ((DSSPublicKey) pubK).getEncoded(IKeyPairCodec.X509_FORMAT);
    PublicKey newPubK = new DSSKeyPairX509Codec().decodePublicKey(pk);
    harness.check(pubK.equals(newPubK),
                  "DSS public key ASN.1 encoder/decoder test");
  }
View Full Code Here


    harness.checkPoint("testPublicKeyValueOf");

    kp = kpg.generate();
    byte[] pk;

    DSAPublicKey p1 = (DSAPublicKey) kp.getPublic();

    pk = ((DSSPublicKey) p1).getEncoded(IKeyPairCodec.RAW_FORMAT);
    PublicKey p2 = DSSPublicKey.valueOf(pk);
    harness.check(p1.equals(p2),
                  "DSS public key valueOf(<raw-value>) test");

    pk = ((DSSPublicKey) p1).getEncoded(IKeyPairCodec.X509_FORMAT);
    PublicKey p3 = DSSPublicKey.valueOf(pk);
    harness.check(p1.equals(p3),
                  "DSS public key valueOf(<x509-value>) test");
  }
View Full Code Here

  public void test(TestHarness harness)
  {
    harness.checkPoint("TestOfDSSSignature");

    DSAPublicKey publicK = new DSSPublicKey(Registry.ASN1_ENCODING_ID, p, q, g, y);
    DSAPrivateKey privateK = new DSSPrivateKey(Registry.ASN1_ENCODING_ID, p, q, g, x);

    DSSSignature alice = new DSSSignature();
    DSSSignature bob = (DSSSignature) alice.clone();
View Full Code Here

    private static final class PublicKeyComparator implements Comparator<PublicKey> {

        public int compare(PublicKey a, PublicKey b) {
            if (a instanceof DSAPublicKey) {
                if (b instanceof DSAPublicKey) {
                    DSAPublicKey da = (DSAPublicKey) a;
                    DSAPublicKey db = (DSAPublicKey) b;
                    int r = da.getParams().getG().compareTo(db.getParams().getG());
                    if (r != 0) {
                        return r;
                    }
                    r = da.getParams().getP().compareTo(db.getParams().getP());
                    if (r != 0) {
                        return r;
                    }
                    r = da.getParams().getQ().compareTo(db.getParams().getQ());
                    if (r != 0) {
                        return r;
                    }
                    return da.getY().compareTo(db.getY());
                } else {
                    return -1;
                }
            } else if (a instanceof RSAPublicKey) {
                if (b instanceof RSAPublicKey) {
                    RSAPublicKey da = (RSAPublicKey) a;
                    RSAPublicKey db = (RSAPublicKey) b;
                    int r = da.getPublicExponent().compareTo(db.getPublicExponent());
                    if (r != 0) {
                        return r;
                    }
                    return da.getModulus().compareTo(db.getModulus());
                } else {
                    return -1;
                }
            } else {
                throw new IllegalArgumentException("Only RSA and DAS keys are supported.");
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

    assertEquals("SHA1WithECDSA", OCSPUtil.getSigningAlgFromAlgSelection("SHA1WithECDSA;SHA1WithDSA", ecdsa));
    assertEquals("SHA1WithECDSA", OCSPUtil.getSigningAlgFromAlgSelection("SHA1WithDSA;SHA1WithRSA;SHA1WithECDSA", ecdsa));
    assertEquals("SHA1WithECDSA", OCSPUtil.getSigningAlgFromAlgSelection("SHA1WithECDSA", ecdsa));
    assertEquals("SHA1WithECDSA", OCSPUtil.getSigningAlgFromAlgSelection("SHA1WithDSA;SHA1WithECDSA", ecdsa));
   
    DSAPublicKey dsa = new MockDSAPublicKey();
    assertEquals("SHA1WithDSA", OCSPUtil.getSigningAlgFromAlgSelection("SHA1WithECDSA;SHA1WithDSA", dsa));
    assertEquals("SHA1WithDSA", OCSPUtil.getSigningAlgFromAlgSelection("SHA256WithECDSA;SHA1WithECDSA;SHA1WithDSA", dsa));
    assertEquals("SHA1WithDSA", OCSPUtil.getSigningAlgFromAlgSelection("SHA1WithDSA", dsa));
    assertEquals("SHA1WithDSA", OCSPUtil.getSigningAlgFromAlgSelection("SHA1WithECDSA;SHA1WithDSA", dsa));
   
View Full Code Here

      } else {
        // We support the key, but we don't know the key length
        len = 0;
      }
    } else if (pk instanceof DSAPublicKey) {
      final DSAPublicKey dsapub = (DSAPublicKey) pk;
      if ( dsapub.getParams() != null ) {
        len = dsapub.getParams().getP().bitLength();
      } else {
        len = dsapub.getY().bitLength();
      }
    }
    return len;
  }
View Full Code Here

      log.debug("getKeyGenSpec: RSA");
      final RSAPublicKey rpk = (RSAPublicKey)pk;
      ret = new RSAKeyGenParameterSpec(getKeyLength(pk), rpk.getPublicExponent());
    } else if (pk instanceof DSAPublicKey) {
      log.debug("getKeyGenSpec: DSA");
      final DSAPublicKey dpk = (DSAPublicKey)pk;
      final DSAParams params = dpk.getParams();
      ret = new DSAParameterSpec(params.getP(), params.getQ(), params.getG());
    } else if (pk instanceof ECPublicKey) {
      log.debug("getKeyGenSpec: ECPublicKey");
      final ECPublicKey ecpub = (ECPublicKey) pk;
      final java.security.spec.ECParameterSpec sunsp = ecpub.getParams();
View Full Code Here

            ps.println("  the public value y: "+dh.getY().toString(16));
            return;
        }
        if ( publK instanceof DSAPublicKey ) {
            ps.println("DSA key:");
            final DSAPublicKey dsa = (DSAPublicKey)publK;
            ps.println("  the public value y: "+dsa.getY().toString(16));
            return;
        }
    }
View Full Code Here

            assertEquals(AlgorithmConstants.SIGALG_SHA1_WITH_DSA, sigAlg);
            assertTrue("Error in created ca certificate", cert.getSubjectDN().toString().equals("CN=TESTDSA"));
            assertTrue("Creating CA failed", info.getSubjectDN().equals("CN=TESTDSA"));
            PublicKey pk = cert.getPublicKey();
            if (pk instanceof DSAPublicKey) {
                DSAPublicKey rsapk = (DSAPublicKey) pk;
                assertEquals(rsapk.getAlgorithm(), "DSA");
            } else {
                assertTrue("Public key is not DSA", false);
            }
            assertTrue("CA is not valid for the specified duration.", cert.getNotAfter().after(
                    new Date(new Date().getTime() + 10 * 364 * 24 * 60 * 60 * 1000L))
 
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.