Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Decrypt Password File

843811Jan 6 2010 — edited Jan 6 2010
Evening. I am totally new to security. after hours of reading about keys and de-enCryption I created this experiment class, that most is copy&paste from sun. All I need is a class that in a simple way decrypt an password file.
Am I even close to the best solution? Code below has two errors, both says "cant find symbol" when mouse over in NetBeans.

public class EnDeCrypt {
   static byte[] encodedAlgParams;

    public static KeyPair myKey()throws Exception{
        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("PBE");
        keyPairGenerator.initialize(1024);
        KeyPair keyPair = keyPairGenerator.genKeyPair();
        return keyPair;
    }

    public static void enCrypt() throws Exception{
        try {
            Cipher c = Cipher.getInstance("PBEWithMD5AndDES");
            c.init(Cipher.ENCRYPT_MODE, myKey());  // *1* <---mouse over c.init says "cant find symbol"
            byte[] cipherText = c.doFinal(text.getBytes());
            AlgorithmParameters algParams = c.getParameters();
            encodedAlgParams = algParams.getEncoded();
            } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(EnDeCrypt.class.getName()).log(Level.SEVERE, null, ex);
            } catch (NoSuchPaddingException ex) {
            Logger.getLogger(EnDeCrypt.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public static void deCrypt(String text) throws Exception {
        AlgorithmParameters algParams;
        algParams =  AlgorithmParameters.getInstance("PBEWithMD5AndDES");
        algParams.init(encodedAlgParams);
        Cipher c = Cipher.getInstance("PBEWithMD5AndDES");
        c.init(Cipher.DECRYPT_MODE, myKey, algParams);// *2*<-- mouse over myKey() says, "cant find this symbol"
    }

}
{code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 3 2010
Added on Jan 6 2010
9 comments
1,831 views