如何使用自定义主密钥来生成普通密钥和使用Java加密密钥

发布于 2025-02-01 16:05:14 字数 975 浏览 4 评论 0原文

我正在阅读亚马逊密钥管理系统 docs 。我试图自己实施加密和解密工作流程。我正在使用此Java代码来生成一个自定义主密钥:

  private static SecretKey generateMasterKey() throws NoSuchAlgorithmException {
    KeyGenerator keyGen = null;

    keyGen = KeyGenerator.getInstance("AES"); 
    
    keyGen.init(256); // 256 bit key
    SecretKey masterKey = keyGen.generateKey();
    return masterKey;
  }

下一步是使用自定义主密钥生成2种键,加密键和Uncrypt键下一步的密码)。我想使用Uncantrypt密钥来加密密码,并将密码加密内容和加密文本加密在数据库中。如何从自定义主密钥中生成加密密钥和Uncrypt密钥?像图像这样的两个键:

”在此处输入图像说明”

I am reading the amazon key management system docs. I have tried to implement the encrypt and decrypt workflow by myself. I am using this java code to generate a custom master key like this:

  private static SecretKey generateMasterKey() throws NoSuchAlgorithmException {
    KeyGenerator keyGen = null;

    keyGen = KeyGenerator.getInstance("AES"); 
    
    keyGen.init(256); // 256 bit key
    SecretKey masterKey = keyGen.generateKey();
    return masterKey;
  }

The next step is to use the custom master key to generate 2 types of key, the encrypt key and unencrypt key (I do not know how to explain the key name the right way, the key could encrypt the password for the next step). I want to use the unencrypt key to encrypt the password and store the password encrypt content and encrypt text in database. How to generate the encrypt key and unencrypt key from the custom master key? The two keys like the image:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文