如何使用 Python 中的 JCEKS 密钥库进行 AES 加密?

How to use a JCEKS Keystore in Python for AES Encryption?

我有一个包含机密条目的 JCEKS 文件。我应该使用密钥库中的这个秘密条目并使用它来使用 Python.

执行 AES 加密

我能够使用 Python 中的 pyjks 库加载 Python 中的 KeyStore 文件。

我可以通过尝试以下操作来查看我的秘密条目 -

import jks

key_store = jks.KeyStore.load("path/to/keystore", "keystorepass")

key_store.entries

其中return以下值

{
    'mysecretentry': <jks.jks.SecretKeyEntry at 0x7fd676e65130>
}

但我不确定如何访问此密钥,以便我可以将其用作我的 AES 加密密钥

from Crypto.Cipher import AES

cipher = AES.new(mysecretentry, AES.MODE_CBC, iv)

我们可以通过简单的

获取存储在Keystore中的安全密钥
secure_key = key_store.entries['mysecretentry'].__getattr__('key')

这会 return 类似于 -

b"^\x88H\x98\xda(\x04qQ\xd0\xe5o\x8d\xc6)'s`=\rj\xab\xbd\xd6*\x11\xefr\x1d\x15B\xd8"

以上secure_key可用于AES加密