0

我有一个应用程序,它使用 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));
4

1 回答 1

0

现在结束这个问题,因为 ntoskml 和 Eilke 的评论是正确的;PBE 是一种仅限 java 的密码学,因此我无法从 Postgresql 解密它。所以最后我不得不想出一个Java/JDBC解决方案来解决这个问题。

于 2014-08-06T16:18:38.107 回答