Package java.security.spec

Examples of java.security.spec.KeySpec


        catch (Exception e)
        {
            fail("unexpected exception.", e);
        }
       
        KeySpec ks = null;
        SecretKey secKey = null;
        byte[] bb = new byte[24];

        try
        {
            skF.getKeySpec(null, null);
           
            fail("failed exception test - no exception thrown");
        }
        catch (InvalidKeySpecException e)
        {
            // ignore okay
        }
        catch (Exception e)
        {
            fail("failed exception test.", e);
        }
        try
        {
            ks = (KeySpec)new DESedeKeySpec(bb);
            skF.getKeySpec(null, ks.getClass());
           
            fail("failed exception test - no exception thrown");
        }
        catch (InvalidKeySpecException e)
        {
View Full Code Here


    } else{
      classkeyspec=Class.forName(FinalValue.ALGORITHM_DES_CLASS);
    }
   
    Constructor constructor = classkeyspec.getConstructor(new Class[]{byte[].class});
    KeySpec dks = (KeySpec) constructor.newInstance(new Object[]{rawKeyData});
    // ����һ����Կ������Ȼ��������DESKeySpecת����SecretKey����
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(algorithm);
    SecretKey key = keyFactory.generateSecret(dks);
    // Cipher����ʵ����ɼ��ܲ���
    Cipher cipher = Cipher.getInstance(algorithm);
View Full Code Here

    }else{
      classkeyspec=Class.forName(FinalValue.ALGORITHM_DES_CLASS);
       
    }
    Constructor constructor = classkeyspec.getConstructor(new Class[]{byte[].class});
    KeySpec dks = (KeySpec) constructor.newInstance(new Object[]{rawKeyData}); //new DESKeySpec(rawKeyData);
    // ����һ����Կ������Ȼ��������DESKeySpec����ת����Secret Key����
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(algorithm);
    SecretKey key = keyFactory.generateSecret(dks);
    // Cipher����ʵ����ɽ��ܲ���
    Cipher cipher = Cipher.getInstance(algorithm);
View Full Code Here

        }
    }

    private static byte[] cipher(String key, byte[] passedBytes, int cipherMode) throws EncryptionException {
        try {
            final KeySpec keySpec = new DESedeKeySpec(stringToByteArray(key));
            final SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede");
            final Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");
            final SecretKey secretKey = keyFactory.generateSecret(keySpec);
            cipher.init(cipherMode, secretKey);
            return cipher.doFinal(passedBytes);
View Full Code Here

    {
        int         keyType = dIn.read();
        String      format = dIn.readUTF();
        String      algorithm = dIn.readUTF();
        byte[]      enc = new byte[dIn.readInt()];
        KeySpec     spec;

        dIn.readFully(enc);

        if (format.equals("PKCS#8") || format.equals("PKCS8"))
        {
View Full Code Here

     * The test checks out that the method returns DSAPublicKey
     * if argument is "DSAPublicKeySpec"
     */
    public final void testGeneratePublicKeySpec03() throws Exception {

        KeySpec keySpec = (KeySpec) new DSAPublicKeySpec(publicY, publicP, publicQ, publicG);

        checkPublicKeys( (DSAPublicKey) kf.generatePublic(keySpec) );
    }
View Full Code Here

     * The test checks out that the method returns DSAPrivateKey
     * if argument is "DSAPrivateKeySpec"
     */
    public final void testGeneratePrivateKeySpec03() throws Exception {

        KeySpec keySpec = (KeySpec) new DSAPrivateKeySpec(privateX,
                                                          privateP, privateQ, privateG);

        checkPrivateKeys( (DSAPrivateKey) kf.generatePrivate(keySpec) );
    }
View Full Code Here

     *    expected "DSAPublicKeySpec" or "X509EncodedKeySpec", and
     * 2) DSAPublickey object generated from KeySpec is equal a "publicKey" argument.
     */
    public final void testGetKeySpec03() throws Exception {

        KeySpec ks;

        ks = kf.getKeySpec( publicKey, DSAPublicKeySpec.class);
        checkPublicKeys( (DSAPublicKey) kf.generatePublic((DSAPublicKeySpec) ks) );

        ks = kf.getKeySpec( publicKey, X509EncodedKeySpec.class);
View Full Code Here

          expected "DSAPrivateKeySpec" or "PKCS8EncodedKeySpec", and
     * 2) DSAPublickey object generated from KeySpec is equal a "privateKey" argument.
     */
    public final void testGetKeySpec04() throws Exception {

        KeySpec ks;

        ks = kf.getKeySpec( privateKey, DSAPrivateKeySpec.class);
        checkPrivateKeys( (DSAPrivateKey) kf.generatePrivate((DSAPrivateKeySpec) ks) );

        ks = kf.getKeySpec( privateKey, PKCS8EncodedKeySpec.class);
View Full Code Here

        KeyPair keys = keyGen.generateKeyPair();
        if (keepalive != null) {
          keepalive.interrupt();
        }

        KeySpec privateKeySpec = fact.getKeySpec(keys.getPrivate(),
            getPrivateKeySpecClass(keyfactAlgs[i]));
        PrivateKey privateKey = fact.generatePrivate(privateKeySpec);
        boolean samePrivate = Arrays.equals(keys.getPrivate()
            .getEncoded(), privateKey.getEncoded());
        assertTrue(
View Full Code Here

TOP

Related Classes of java.security.spec.KeySpec

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.