找回存储在DBeaver连接中的数据库密码

一、拿到 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 串,可以借助工具 https://www.json.cn/ 查看)

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

在这里插入图片描述

  • 11
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值