我有一个应用程序,它使用 Java javax.crypto 包来加密字符串并将它们存储在 postgresql 数据库中。我们需要从 postgres SQL 中解密这些字符串。我知道 postgresSQL 包 pgcrypto 但我不知道应该使用哪个 pgcrypto 函数来解密字符串。java 代码使用加密“PBEWithMD5AndDES”算法,我在 pgcrypto 包中找不到相应的算法。
例如,如果私钥是“a_private_key”,则应用程序代码使用以下函数来生成密钥并加密字符串。
SecretKey secretKey = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(new PBEKeySpec("a_private_key".toCharArray()));
Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES")
cipher.init(Cipher.ENCRYPT_MODE, secretKey,
new PBEParameterSpec(
new byte[] { (byte) 0x30, (byte) 0x31, (byte) 0x32, (byte) 0x33,
(byte) 0x34, (byte) 0x35, (byte) 0x36, (byte) 0x37, },
15);
byte[] crypted = cipher.doFinal("StringToEncrypt".getBytes(UTF8));