Package java.security.interfaces

Examples of java.security.interfaces.DSAPrivateKey


     *             public key
     */
    public static PublicKey derivePublicKey(PrivateKey key) throws KeyException {
        KeyFactory factory;
        if (key instanceof DSAPrivateKey) {
            DSAPrivateKey dsaKey = (DSAPrivateKey) key;
            DSAParams keyParams = dsaKey.getParams();
            BigInteger y = keyParams.getQ().modPow(dsaKey.getX(), keyParams.getP());
            DSAPublicKeySpec pubKeySpec = new DSAPublicKeySpec(y, keyParams.getP(), keyParams.getQ(), keyParams.getG());

            try {
                factory = KeyFactory.getInstance("DSA");
                return factory.generatePublic(pubKeySpec);
View Full Code Here


    catch (IllegalArgumentException x)
      {
        harness.check(true, "Recognised unknown public key format ID");
      }

    DSAPrivateKey secK = (DSAPrivateKey) kp.getPrivate();
    try
      {
        ((DSSPrivateKey) secK).getEncoded(0);
        harness.fail("Private key succeeded with unknown format ID");
      }
View Full Code Here

    pk = ((DSSPublicKey) pubK).getEncoded(IKeyPairCodec.RAW_FORMAT);
    PublicKey newPubK = codec.decodePublicKey(pk);
    harness.check(pubK.equals(newPubK),
                  "DSS public key Raw encoder/decoder test");

    DSAPrivateKey secK = (DSAPrivateKey) kp.getPrivate();
    pk = ((DSSPrivateKey) secK).getEncoded(IKeyPairCodec.RAW_FORMAT);
    PrivateKey newSecK = codec.decodePrivateKey(pk);
    harness.check(secK.equals(newSecK),
                  "DSS private key Raw encoder/decoder test");
  }
View Full Code Here

    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),
View Full Code Here

    harness.checkPoint("testPrivateKeyValueOf");

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

    DSAPrivateKey p1 = (DSAPrivateKey) kp.getPrivate();

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

    pk = ((DSSPrivateKey) p1).getEncoded(IKeyPairCodec.PKCS8_FORMAT);
    PrivateKey p3 = DSSPrivateKey.valueOf(pk);
    harness.check(p1.equals(p3),
                  "DSS private key valueOf(<pkcs8-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();

    byte[] message = "1 if by land, 2 if by sea...".getBytes();
View Full Code Here

            final DHPrivateKey dh = (DHPrivateKey)privK;
            final BigInteger result = dh.getX();
            return result!=null && result.bitLength()>0;
        }
        if ( privK instanceof DSAPrivateKey) {
            final DSAPrivateKey dsa = (DSAPrivateKey)privK;
            final BigInteger result = dsa.getX();
            return result!=null && result.bitLength()>0;
        }
        return false;
    }
View Full Code Here

            if (keySpec == null) {
                throw new NullPointerException(Messages
                        .getString("security.19E")); //$NON-NLS-1$
            }
            if (key instanceof DSAPrivateKey) {
                DSAPrivateKey privateKey = (DSAPrivateKey) key;

                if (keySpec.equals(DSAPrivateKeySpec.class)) {

                    x = privateKey.getX();

                    DSAParams params = privateKey.getParams();

                    p = params.getP();
                    q = params.getQ();
                    g = params.getG();
View Full Code Here

    protected Key engineTranslateKey(Key key) throws InvalidKeyException {

        if (key != null) {
            if (key instanceof DSAPrivateKey) {

                DSAPrivateKey privateKey = (DSAPrivateKey) key;
                DSAParams params = privateKey.getParams();

                try {
                    return engineGeneratePrivate(new DSAPrivateKeySpec(
                            privateKey.getX(), params.getP(), params.getQ(),
                            params.getG()));
                } catch (InvalidKeySpecException e) {
                    // Actually this exception shouldn't be thrown
                    throw new InvalidKeyException(Messages.getString(
                            "security.1A0", e)); //$NON-NLS-1$
View Full Code Here

        pubKeyFactoryBean.setLocation(pubKeyResource);
        privKeyFactoryBean.setLocation(privKeyResource);
        pubKeyFactoryBean.afterPropertiesSet();
        privKeyFactoryBean.afterPropertiesSet();
       
        final DSAPrivateKey privateKey = (DSAPrivateKey) privKeyFactoryBean.getObject();
        final DSAPublicKey publicKey = (DSAPublicKey) pubKeyFactoryBean.getObject();
       
        final MockHttpServletRequest request = new MockHttpServletRequest();
       
        final String SAMLRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><samlp:AuthnRequest xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" ID=\"5545454455\" Version=\"2.0\" IssueInstant=\"Value\" ProtocolBinding=\"urn:oasis:names.tc:SAML:2.0:bindings:HTTP-Redirect\" ProviderName=\"https://localhost:8443/myRutgers\" AssertionConsumerServiceURL=\"https://localhost:8443/myRutgers\"/>";
View Full Code Here

TOP

Related Classes of java.security.interfaces.DSAPrivateKey

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.