独立的java程序来解密密码

时间:2012-09-10 11:18:29

标签: encryption

我必须编写一个独立的java程序来解密文件中的密码,使用Symmetric密钥进行密码解密。我之前没有加密和解密。任何人都可以提出任何建议我该怎么做。我需要你的指导。

1 个答案:

答案 0 :(得分:0)

也许你需要这样的东西

    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");

以下是一些资源:

  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(这也使用文件)