Package java.security.interfaces

Examples of java.security.interfaces.DSAPrivateKey


            RSAPrivateCrtKey    rsK = (RSAPrivateCrtKey)privKey.getKey();
           
            secKey = new RSASecretBCPGKey(rsK.getPrivateExponent(), rsK.getPrimeP(), rsK.getPrimeQ());
            break;
        case PGPPublicKey.DSA:
            DSAPrivateKey       dsK = (DSAPrivateKey)privKey.getKey();
           
            secKey = new DSASecretBCPGKey(dsK.getX());
            break;
        case PGPPublicKey.ELGAMAL_ENCRYPT:
        case PGPPublicKey.ELGAMAL_GENERAL:
            ElGamalPrivateKey   esK = (ElGamalPrivateKey)privKey.getKey();
           
View Full Code Here


                {
                    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());
                sKey = (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");
                }
               
                //
View Full Code Here

        if (!(o instanceof DSAPrivateKey))
        {
            return false;
        }
       
        DSAPrivateKey other = (DSAPrivateKey)o;
       
        return this.getX().equals(other.getX())
            && 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

        PrivateKey    key)
        throws InvalidKeyException
    {
        if (key instanceof DSAPrivateKey)
        {
            DSAPrivateKey    k = (DSAPrivateKey)key;

            return new DSAPrivateKeyParameters(k.getX(),
                new DSAParameters(k.getParams().getP(), k.getParams().getQ(), k.getParams().getG()));
        }
                       
        throw new InvalidKeyException("can't identify DSA private key.");
    }
View Full Code Here

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

        PKCS8EncodedKeySpec ks;
        DSAPrivateKey prKey;

        final BigInteger x = privateX;
        final BigInteger p = privateP;
        final BigInteger q = privateQ;
        final BigInteger g = privateG;

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

        prKey = new DSAPrivateKey () {

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

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

        PKCS8EncodedKeySpec ks;
        DSAPrivateKey prKey;

        final BigInteger x = privateX;
        final BigInteger p = privateP;
        final BigInteger q = privateQ;
        final BigInteger g = privateG;

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

        prKey = new DSAPrivateKey () {

                  public BigInteger getX() { return x; }
                  public DSAParams getParams() {
                      return  (DSAParams)(new DSAParameterSpec(p, q, g));
                  }
                  public String getAlgorithm() { return "DSA"; }
                  public byte[] getEncoded()   { return enc2; }
                  public String getFormat()    { return "PKCS8"; }
              };

        ks = kf.getKeySpec(prKey, PKCS8EncodedKeySpec.class);
        prKey = (DSAPrivateKey) kf.generatePrivate((KeySpec)ks);

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

        final BigInteger g = privateG;

        final byte enc1[] = new byte[lng];
        System.arraycopy(privateEncoding, 0, enc1, 0, lng)// enc1 contains incorrect encoding

        DSAPrivateKey prKey = new DSAPrivateKey () {

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

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

        DSAPrivateKey prKey = new DSAPrivateKey () {

                  public BigInteger getX() { return x; }
                  public DSAParams getParams() {
                      return  (DSAParams)(new DSAParameterSpec(p, q, g));
                  }
                  public String getAlgorithm() { return "DSA"; }
                  public byte[] getEncoded()   { return enc2; }
                  public String getFormat()    { return "PKCS8"; }
              };

        PKCS8EncodedKeySpec ks = kf.getKeySpec(prKey, PKCS8EncodedKeySpec.class);

        prKey = (DSAPrivateKey) kf.generatePrivate((KeySpec)ks);
        prKey = (DSAPrivateKey) kf.translateKey( (Key)prKey );

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

          && dsa1.getParams().getP().equals(dsa2.getParams().getP())
          && dsa1.getParams().getQ().equals(dsa2.getParams().getQ());

    } else if (key1 instanceof DSAPrivateKey
        && key2 instanceof DSAPrivateKey) {
      DSAPrivateKey dsa1 = ((DSAPrivateKey) key1);
      DSAPrivateKey dsa2 = ((DSAPrivateKey) key2);
      return dsa1.getX().equals(dsa2.getX())
          && dsa1.getParams().getG().equals(dsa2.getParams().getG())
          && dsa1.getParams().getP().equals(dsa2.getParams().getP())
          && dsa1.getParams().getQ().equals(dsa2.getParams().getQ());
    } else {
      return false;
    }
  }
View Full Code Here

        final BigInteger pp = p;
        final BigInteger qq = q;
        final BigInteger gg = g;
        final BigInteger xx = x;

        return new DSAPrivateKey() {

            public BigInteger getX() {
                return xx;
            }
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.