Package java.security.interfaces

Examples of java.security.interfaces.DSAPublicKey


        final BigInteger g = publicG;

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

        DSAPublicKey pubKey = new DSAPublicKey () {

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


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

        DSAPublicKey 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"; }
              };

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

        pubKey = (DSAPublicKey) kf.generatePublic((KeySpec)ks);
        pubKey = (DSAPublicKey) kf.translateKey( (Key)pubKey );

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

                 isEqual(key, keys.getPrivate()));
  }

  private boolean isEqual(Key key1, Key key2) {
    if (key1 instanceof DSAPublicKey && key2 instanceof DSAPublicKey) {
      DSAPublicKey dsa1 = ((DSAPublicKey) key1);
      DSAPublicKey dsa2 = ((DSAPublicKey) key2);
      return dsa1.getY().equals(dsa2.getY())
          && dsa1.getParams().getG().equals(dsa2.getParams().getG())
          && 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

    public void test_initializeLjava_security_spec_AlgorithmParameterSpec()
            throws Exception {
        // create DSAParams
        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("DSA");
        keyPairGenerator.initialize(1024);
        DSAPublicKey key = (DSAPublicKey) keyPairGenerator.genKeyPair()
                .getPublic();
        DSAParams params = key.getParams();

        KeyPairGenerator keyPair = KeyPairGenerator.getInstance("DSA");
        keyPair.initialize(new DSAParameterSpec(params.getP(), params.getQ(),
                params.getG()));
    }
View Full Code Here

    public void test_initializeLjava_security_spec_AlgorithmParameterSpecLjava_security_SecureRandom()
            throws Exception {
        // create DSAParams
        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("DSA");
        keyPairGenerator.initialize(1024);
        DSAPublicKey key = (DSAPublicKey) keyPairGenerator.genKeyPair()
                .getPublic();
        DSAParams params = key.getParams();

        KeyPairGenerator keyPair = KeyPairGenerator.getInstance("DSA");
        keyPair.initialize(new DSAParameterSpec(params.getP(), params.getQ(),
                params.getG()), new SecureRandom());
    }
View Full Code Here

        final BigInteger pp = p;
        final BigInteger qq = q;
        final BigInteger gg = g;
        final BigInteger yy = y;

        return new DSAPublicKey() {

            public BigInteger getY() {
                return yy;
            }
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()))
        {
            fail("public number not decoded properly");
        }
       
        if (!k1.getParams().getG().equals(((DSAPublicKey)vKey).getParams().getG()))
        {
            fail("public generator not decoded properly");
        }
       
        if (!k1.getParams().getP().equals(((DSAPublicKey)vKey).getParams().getP()))
        {
            fail("public p value not decoded properly");
        }
       
        if (!k1.getParams().getQ().equals(((DSAPublicKey)vKey).getParams().getQ()))
        {
            fail("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()))
        {
            fail("private number not decoded properly");
        }
       
        if (!k2.getParams().getG().equals(((DSAPrivateKey)sKey).getParams().getG()))
        {
            fail("private generator not decoded properly");
        }
       
        if (!k2.getParams().getP().equals(((DSAPrivateKey)sKey).getParams().getP()))
        {
            fail("private p value not decoded properly");
        }
       
        if (!k2.getParams().getQ().equals(((DSAPrivateKey)sKey).getParams().getQ()))
        {
            fail("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()))
        {
            fail("public number not decoded properly");
        }
       
        if (!k1.getParams().getG().equals(((DSAPublicKey)vKey).getParams().getG()))
        {
            fail("public generator not decoded properly");
        }
       
        if (!k1.getParams().getP().equals(((DSAPublicKey)vKey).getParams().getP()))
        {
            fail("public p value not decoded properly");
        }
       
        if (!k1.getParams().getQ().equals(((DSAPublicKey)vKey).getParams().getQ()))
        {
            fail("public q value not decoded properly");
        }
       
        pkcs8 = new PKCS8EncodedKeySpec(k2.getEncoded());
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

    }

    private String getString(PublicKey key) throws FailedLoginException {
        try {
            if (key instanceof DSAPublicKey) {
                DSAPublicKey dsa = (DSAPublicKey) key;
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                DataOutputStream dos = new DataOutputStream(baos);
                write(dos, "ssh-dss");
                write(dos, dsa.getParams().getP());
                write(dos, dsa.getParams().getQ());
                write(dos, dsa.getParams().getG());
                write(dos, dsa.getY());
                dos.close();
                return base64Encode(baos.toByteArray());
            } else if (key instanceof RSAKey) {
                RSAPublicKey rsa = (RSAPublicKey) key;
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
View Full Code Here

   @Test
   public void testEncodeAsOpenSSH() throws IOException, InvalidKeySpecException, NoSuchAlgorithmException {
      String dsa = Strings2.toStringAndClose(getClass().getResourceAsStream("/ssh-dsa.txt"));
      DSAPublicKeySpec spec = DSAKeys.publicKeySpecFromOpenSSH(dsa);
      DSAPublicKey key = (DSAPublicKey) KeyFactory.getInstance("DSA").generatePublic(spec);

      assertEquals(DSAKeys.encodeAsOpenSSH(key), 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.