1

I have to write a standalone java program to decrypt password from file,using Symmetric key for password decryption. I didn't work with encryption and decryption before. can anybody give any suggestion how can i do this.I need your guidance.

4

1 に答える 1

0

maybe you need something like this

    private static final String ALGORITHM = "AES";
    ....
    ....
    Key key = new SecretKeySpec(new String("here is your symmetric key").getBytes(), ALGORITHM);
    Cipher c = Cipher.getInstance(ALGORITHM);
    //dencript mode (passes the key)
    c.init(Cipher.DECRYPT_MODE, key);
    //Decode base64 to get bytes 
    byte[] encBytes  = new BASE64Decoder().decodeBuffer(encryptedValue);
    // Decrypt 
    byte[] plainTxtBytes  = c.doFinal(encBytes);
    // Decode
    String decryptedValue = new String(plainTxtBytes , "UTF-8");

Here are some resources:

  1. http://www.javamex.com/tutorials/cryptography/symmetric.shtml

  2. http://www.java2s.com/Code/Java/Security/EncryptionandDecryptionusingSymmetricKeys.htm

  3. http://www.flexiprovider.de/examples/ExampleCrypt.html (This uses files as well)

于 2012-09-10T11:35:23.660 に答える