- 浏览: 522087 次
- 性别:
- 来自: 大连
文章分类
- 全部博客 (240)
- Java (25)
- Flex (46)
- Sybase (26)
- Sqlserver (7)
- .NET (1)
- .NET-Silverlight (11)
- Hibernate (5)
- Korn-shell (2)
- Perl (5)
- Unix & Linux (11)
- Ruby (3)
- SVN (2)
- Tomcat (1)
- CSS (5)
- Web (2)
- English (3)
- SQL (9)
- Qlikview (4)
- Spring (7)
- javascript (2)
- weblogic (5)
- iphone (1)
- 网络 (5)
- 随 (23)
- AutoSys (1)
- Hermes (2)
- RPM (2)
- CA (1)
- Operating System (1)
- SSIS (3)
- Windows (2)
- excel (1)
- SSRS (1)
- 活动 (23)
- Eclipse (2)
- Angular (0)
- Python (0)
- AWS (0)
- Android (0)
最新评论
-
devcang:
long t1 = System.nanoTime();
java中取得微秒级的时间 -
Sev7en_jun:
Sev7en_jun 写道 ExternalInterface ...
flex"页面跳转" -
Sev7en_jun:
ExternalInterface.call("fu ...
flex"页面跳转" -
lujinan858:
Incorrect syntax near 'fddActiv ...
Sybase alter 用法 -
Sev7en_jun:
Alter table TestItem drop COLUM ...
Sybase alter 用法
1.使用openssl转换将pem的密钥和证书成der格式
openssl pkcs8 -topk8 -nocrypt -in key.pem -inform PEM -out key.der -outform DER openssl x509 -in cert.pem -inform PEM -out cert.der -outform DER
2.使用java程序ImportKey创建密钥库,可以修改java代码中的密码,别名,文件路径和名字
java ImportKey key.der cert.der
也可以创建后,使用keytool命令修改密码,别名
检查一个keystore中的内容
keytool -list -v -alias mykeypair -keystore mykeystore -storetype JCEKS
参数 -v 指明要列出详细信息
-alias 指明列出指定的别名为mykeypair的keypair信息(不指定则列出所有)
-keystore 指明要列出名字为mykeystore的keystore中的信息
-storetype 指明keystore类型(不指定默认为jks)
ImportKey.java
import java.security.*; import java.io.IOException; import java.io.InputStream; import java.io.FileInputStream; import java.io.DataInputStream; import java.io.ByteArrayInputStream; import java.io.FileOutputStream; import java.security.spec.*; import java.security.cert.Certificate; import java.security.cert.CertificateFactory; import java.util.Collection; import java.util.Iterator; /** * ImportKey.java * * This class imports a key and a certificate into a keystore * ($home/keystore.ImportKey). If the keystore is * already present, it is simply deleted. Both the key and the * certificate file must be in DER-format. The key must be * encoded with PKCS#8-format. The certificate must be * encoded in X.509-format. * * Key format: * openssl pkcs8 -topk8 -nocrypt -in YOUR.KEY -out YOUR.KEY.der * -outform der * Format of the certificate: * openssl x509 -in YOUR.CERT -out YOUR.CERT.der -outform * der * Import key and certificate: * java comu.ImportKey YOUR.KEY.der YOUR.CERT.der * * Caution: the old keystore.ImportKey-file is * deleted and replaced with a keystore only containing YOUR.KEY * and YOUR.CERT. The keystore and the key has no password; * they can be set by the keytool -keypasswd-command for setting * the key password, and the keytool -storepasswd-command to set * the keystore password. * The key and the certificate is stored under the alias * importkey; to change this, use keytool -keyclone. * * Created: Fri Apr 13 18:15:07 2001 * Updated: Fri Apr 19 11:03:00 2002 * * @author Joachim Karrer, Jens Carlberg * @version 1.1 **/ public class ImportKey { /** * Creates an InputStream from a file, and fills it with the complete * file. Thus, available() on the returned InputStream will return the * full number of bytes the file contains * @param fname The filename * @return The filled InputStream * @exception IOException, if the Streams couldn't be created. **/ private static InputStream fullStream ( String fname ) throws IOException { FileInputStream fis = new FileInputStream(fname); DataInputStream dis = new DataInputStream(fis); byte[] bytes = new byte[dis.available()]; dis.readFully(bytes); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); return bais; } /** * Takes two file names for a key and the certificate for the key, * and imports those into a keystore. Optionally it takes an alias * for the key. * The first argument is the filename for the key. The key should be * in PKCS8-format. * The second argument is the filename for the certificate for the key. * If a third argument is given it is used as the alias. If missing, * the key is imported with the alias importkey * The name of the keystore file can be controlled by setting * the keystore property (java -Dkeystore=mykeystore). If no name * is given, the file is named keystore.ImportKey * and placed in your home directory. * @param args [0] Name of the key file, [1] Name of the certificate file * [2] Alias for the key. **/ public static void main ( String args[]) { // change this if you want another password by default String keypass = "importkey"; // change this if you want another alias by default String defaultalias = "importkey"; // change this if you want another keystorefile by default String keystorename = System.getProperty("keystore"); if (keystorename == null) keystorename = System.getProperty("user.home")+ System.getProperty("file.separator")+ "keystore.ImportKey"; // especially this ;-) // parsing command line input String keyfile = ""; String certfile = ""; if (args.length < 2 || args.length>3) { System.out.println("Usage: java comu.ImportKey keyfile certfile [alias]"); System.exit(0); } else { keyfile = args[0]; certfile = args[1]; if (args.length>2) defaultalias = args[2]; } try { // initializing and clearing keystore KeyStore ks = KeyStore.getInstance("JKS", "SUN"); ks.load( null , keypass.toCharArray()); System.out.println("Using keystore-file : "+keystorename); ks.store(new FileOutputStream ( keystorename ), keypass.toCharArray()); ks.load(new FileInputStream ( keystorename ), keypass.toCharArray()); // loading Key InputStream fl = fullStream (keyfile); byte[] key = new byte[fl.available()]; KeyFactory kf = KeyFactory.getInstance("RSA"); fl.read ( key, 0, fl.available() ); fl.close(); PKCS8EncodedKeySpec keysp = new PKCS8EncodedKeySpec ( key ); PrivateKey ff = kf.generatePrivate (keysp); // loading CertificateChain CertificateFactory cf = CertificateFactory.getInstance("X.509"); InputStream certstream = fullStream (certfile); Collection c = cf.generateCertificates(certstream) ; Certificate[] certs = new Certificate[c.toArray().length]; if (c.size() == 1) { certstream = fullStream (certfile); System.out.println("One certificate, no chain."); Certificate cert = cf.generateCertificate(certstream) ; certs[0] = cert; } else { System.out.println("Certificate chain length: "+c.size()); certs = (Certificate[])c.toArray(); } // storing keystore ks.setKeyEntry(defaultalias, ff, keypass.toCharArray(), certs ); System.out.println ("Key and certificate stored."); System.out.println ("Alias:"+defaultalias+" Password:"+keypass); ks.store(new FileOutputStream ( keystorename ), keypass.toCharArray()); } catch (Exception ex) { ex.printStackTrace(); } } }// KeyStore
原文请参见http://knowledge-oracle.blogspot.com/2009/02/import-private-key-and-certificate-in.html
发表评论
-
Tools
2015-04-16 15:29 01. DeleteDuplicateLineFromFile ... -
Java List deepCopy function
2015-03-09 17:00 1156List<String> listA = ne ... -
集成Sqlserver Windows Authentication验证到第三方DB客户端软件中, 如DbVisualizer & Squirrel等
2014-03-18 16:47 1575本方法适用于Java编写的第三方DB客户端软件, 如DbV ... -
linux下解压命令大全和 rpm命令使用简介
2013-09-20 17:25 1503linux下解压命令大全 .t ... -
如何把jdk配置到eclipse里
2013-07-17 15:14 897window -> preference -> ... -
下一步需要深入学习的linux命令
2013-03-19 15:42 911vi grep awk sed find sor ... -
Linux shell grep指令
2013-03-07 15:40 8796grep一般格式为:grep [ ... -
linux shell if 参数
2013-03-07 15:38 925shell 编程中使用到得if ... -
OpenSSL建立自己的CA
2012-03-05 16:05 2027OpenSSL可以使用在Windows上,也可以在Linu ... -
查看linux 的IP
2012-02-23 15:56 886查看linux server的/etc/hosts 文件 ... -
java.lang.NoSuchFieldError: fAugmentations
2012-02-23 10:12 1591错误信息如下: <Feb 22, 2012 2:42: ... -
AutoSys的基本命令
2012-02-09 11:00 31391.cmd sendevent -E FORCE_ST ... -
(转)weblogic下新建domain步骤
2012-01-06 10:45 2430Weblogic新建domain:至WEBLOGIC安装目录下 ... -
JAVA1.5范型
2011-11-02 15:19 1173本文将介绍J2SE 5.0中三个比较重要的特性: 枚举类型, ... -
FTP命令详解
2011-05-23 14:15 849FTP命令是Internet用户使用最频繁的命令之一,不论是 ... -
SFTP服务器的文件管理(转)
2011-04-26 13:59 2101来源(http://forhope.iteye.c ... -
修改weblogic中StuckThreadMaxTime参数
2011-04-04 18:01 32520your_domain->Environment -& ... -
在Spring框架下 使用junit进行单元测试
2010-03-01 15:53 1122package com.yourPackage.test;im ... -
JAVA JNI 使用实例
2010-02-25 21:34 1596JAVA JNI 使用实例 JAVA可以通过JNI接口 ... -
java中调用c(c++)写的dll 文件的实现及步骤(转)
2010-02-25 21:33 1612JNI使用技巧点滴 本文为在 32 位 Windows 平台 ...
相关推荐
如果未指定密钥存储库,则将密钥对导入其中 ~/.用户主目录中的密钥存储库。 密码也可以从stdin读取。 例子: 向Android SDK添加Android平台级证书。 keytool-importkeypair -k ~/.android/debug.keystore -p ...
介绍Ad域服务器证书如何申请,如何导出,如何导入到java秘钥库,地址:https://blog.csdn.net/hc1017/article/details/81293323 实现ssl 修改ad用户密码,禁用启用用户。有两个demo测试文
如何使用密钥管理库导入PEM格式的证书1
Java 密钥库证书导入 通过连接到主机并下载证书,简单地导入 Java 密钥库。 应该使用 https、smtp 或 ldap 证书。 要求 安装了Java。 角色变量 java_certificate_host: example.com java_certificate_port: 443 ...
https密钥和证书访问OceanConnect。。。。。。。。。。。。。。。。。。。。。。。
C#使用IKVM 生成 java AES 密钥并实现加解密,需要引用bin目录下5个dll文件。
keytool 是个密钥和证书管理工具。它使用户能够管理自己的公钥/私钥对及相关证书,用于(通过数字签名)自我认证(用户向别的用户/服务认证自己)或数据完整性以及认证服务。它还允许用户储存他们的通信对等者的公钥...
C#与JAVA调用密钥的格式不一样,需要转换,同时还提供了密钥生成功能
Java生成密钥的实例.7z
实现java代码生成cer证书文件,然后可以通过代码获取 不通过keytool工具。生成密钥对。使用公钥加密。
以XML格式导入导出密钥.rar以XML格式导入导出密钥.rar以XML格式导入导出密钥.rar
OEM证书密钥自动导入工具,定做你自己的系统,是你硬刷主板后的好帮手。
使用自签名版本1X.509证书生成DSA和RSA密钥对条目。 将X.509证书文件导入为受信任的证书。 从PKCS#12和PEM包文件导入密钥对。 克隆并更改密钥对条目和密钥库的密码。 查看密钥库条目,证书文件和SSL/TLS连接中...
生成RSA加密解密使用的密钥对项目
密钥分配(RSA+DES混合加密含源程序) - lly1122334的博客 - CSDN博客 http://blog.csdn.net/lly1122334/article/details/78959639
pem, 使用 node.js 创建 private 密钥和证书 使用 node.js 创建 private 密钥和证书 安装使用npm安装 npm install pem 示例下面是在动态创建SSL密钥/证书以及在端口 443上运行HTTPS服
密钥和证书管理工具.doc
应用场景用于当你使用的是.net技术需要调用对方的接口时,但对方使用的是java语言时需要把对方提供的RSA私钥或者RSA公钥进行转换成.net格式进行使用。否则可能会出现解密失败的情况出现,相反就是你是java技术需要...
这两个工程主要用CSP主要分两个工程 1.CSPTEST 写的比较乱 主要是给当时一个朋友做参考调用的 完成非对称密钥的生成 导入 导出 ...这个工程主要是非对称的密钥的导出和导入 还有就是会话密钥的操作。
c# RSA读取密钥文件pfx cer 签名验签加密解密工具类 1 包含java形式密钥转换成c# c# 形式密钥转换成java