从JCK密钥库中导出密钥 [英] Export secret key from jck key store

查看:147
本文介绍了从JCK密钥库中导出密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个包含密钥的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆