一、拿到 credentials-config.json 文件
1、打开 dbeaver 后,点击 “窗口 — 首选项”

2、找到worksapce path

3、进入 workspace path 的文件夹,再进入到 \general.dbeaver 文件夹,找到文件 credentials-config.json (可以备份一下这个文件,万一不小心改了内容)。

二、对 credentials-config.json 文件解码
1、方法一:
如果你有安装 ubuntu、centos 等这些 linux 操作系统,并且系统上安装了 openssl,则可以使用 openssl 对credentials-config.json文件解码(以 centos 系统为例):
(1)先把文件复制到 centos 系统某个目录下

(2)还是在这个目录下,使用如下命令
openssl aes-128-cbc -d \ -k babb4a9f774ab853c96c2d653dfe544a \ -iv 00000000000000000000000000000000 \ -in credentials-config.json | \ dd bs=1 skip=16 2>/dev/null

(3)命令执行后,就得到解码后的json字符串(为了方便查看 json 串,可以借助工具 查看)
2、方法二:
如果没有 linux 系统和 openssl ,可以用 windows 系统和 java
(1)在某个文件夹新建文件 defaultvalueencryptor.txt ,把下面这段代码粘贴进去保存。
import javax.crypto.cipher;
import javax.crypto.cipherinputstream;
import javax.crypto.secretkey;
import javax.crypto.spec.ivparameterspec;
import javax.crypto.spec.secretkeyspec;
import java.io.bytearrayinputstream;
import java.io.bytearrayoutputstream;
import java.io.inputstream;
import java.nio.file.files;
import java.nio.file.paths;
public class defaultvalueencryptor {
public static final string cipher_name = "aes/cbc/pkcs5padding";
public static final string key_algorithm = "aes";
private final secretkey secretkey;
private final cipher cipher;
public defaultvalueencryptor(secretkey secretkey) {
this.secretkey = secretkey;
try {
this.cipher = cipher.getinstance(cipher_name);
} catch (exception e) {
system.out.println("internal error during encrypted init" + e);
throw new runtimeexception(e);
}
}
public byte[] decryptvalue(byte[] value) {
try (inputstream bytestream = new bytearrayinputstream(value)) {
byte[] fileiv = new byte[16];
bytestream.read(fileiv);
cipher.init(cipher.decrypt_mode, secretkey, new ivparameterspec(fileiv));
try (cipherinputstream cipherin = new cipherinputstream(bytestream, cipher)) {
bytearrayoutputstream resultbuffer = new bytearrayoutputstream();
int buffersize = 100;
byte[] buffer = new byte[buffersize];
while ((buffersize = cipherin.read(buffer)) != -1) {
resultbuffer.write(buffer, 0,buffersize);
}
return resultbuffer.tobytearray();
}
} catch (exception e) {
system.out.println("error decrypting value" + e);
throw new runtimeexception(e);
}
}
public static void main(string[] args) throws exception {
if (args.length != 1) {
system.err.println("plese input param1: full path to your credentials-config.json file");
system.exit(1);
}
final byte[] local_key_cache = new byte[]{-70, -69, 74, -97, 119, 74, -72, 83, -55, 108, 45, 101, 61, -2, 84, 74};
secretkey aes = new secretkeyspec(local_key_cache, key_algorithm);
defaultvalueencryptor encryptor = new defaultvalueencryptor(aes);
byte[] credentialsconfigbytessecret = files.readallbytes(paths.get(args[0]));
byte[] credentialsconfigbytesplain = encryptor.decryptvalue(credentialsconfigbytessecret);
system.out.println(new string(credentialsconfigbytesplain));
}
}(2)然后再把文件名的后缀从 .txt 改为 .java ,并把之前的 credentials-config.json 文件也复制到同个目录下。

(3)cmd 命令行进入到该目录,然后依次执行命令 ,即可。
javac defaultvalueencryptor.java java defaultvalueencryptor credentials-config.json

总结
到此这篇关于如何找回存储在dbeaver连接中数据库密码的文章就介绍到这了,更多相关找回dbeaver数据库密码内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论