从JCK密钥库中导出密钥 [英] Export secret key from jck key store
问题描述
我们有一个包含密钥的jck密钥库(jceks)格式.它是使用keytool命令
We have a jck keystore (jceks) format containing a secret key. It was generated using keytool command
keytool -genseckey -alias mykey -keyalg AES -keysize 256 -storetype jceks -keystore mykeystore.jks
keytool -genseckey -alias mykey -keyalg AES -keysize 256 -storetype jceks -keystore mykeystore.jks
我们需要与另一个应用程序共享它,并且它们在使用jck store时似乎有局限性.他们要求将密钥导出并提供给他们.
We need to share this with another application and they seem to have limitations in working with jck store. They are asking for the key to be exported and supplied to them.
我们尝试了一些工具,但无法导出密钥.是否有命令或解决方法来实现这一目标?
We tried a few tools, but are not able to export the secret key. Is there a command or workaround to achieve this ?
推荐答案
keytool不支持导出秘密密钥.您可以使用KeyStore
api来做到这一点.
keytool doesn't support exporting of Secret Keys. You could use the KeyStore
api to do this.
KeyStore ks = KeyStore.getInstance("JCEKS");
ks.load(new FileInputStream(new File("KEYSTORE_PATH")), "PASSWORD".toCharArray());
SecretKey key = (SecretKey) ks.getKey("ALIAS", "PASSWORD".toCharArray());
System.out.println(new String(Base64.encode(key.getEncoded())));
这篇关于从JCK密钥库中导出密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!