跳至正文

der格式的证书含私钥吗,der证书怎么解析

什么证书包含私钥?什么证书不含私钥?急,谢谢

什么证书包含私钥?什么证书不含私钥?急,谢谢

一般网上银行的数字证书都有私钥,当然也可以不设私钥!不设私钥时,有可能被人盗用而无需密码就能进行网上银行的转帐等!

什么样的证书包含私钥

什么样的证书包含私钥

网银密钥是网银证书的密码.是不可导出的.用K宝或者建行的网盾时候.下载证书以后,会让你设置一个密码的.就好像给网银登录加了一把锁,用这把钥匙才可以登录网银.只有下载证书才用密钥的.还有不用 密钥的情况,那是因为用动态密码口令登录是不用下载证书.主要靠密码的变动来保障密码安全.你看给你开的网银是哪种方式.登录网银看提示就会操作的.呵呵!

如何将证书导入到软件包密钥库

如何将证书导入到软件包密钥库

要导入的证书和私钥必须以 PEM 或 DER 编码的 X.509

证书和私钥形式存在。此外,必须先将任何将您的签名证书与证书颁发机构证书相关联的中间或“链”证书导入到软件包密钥库中,然后才能对软件包进行签名。

注 –

各证书颁发机构可能会颁发不同格式的证书。要将证书和私钥从 PKCS12 文件提取到 PEM 编码的

X.509 文件(适于导入到软件包密钥库),请使用免费软件转换实用程序,例如 OpenSSL。

如果您的私钥进行了加密(通常应该如此),系统将提示您输入口令短语。此外,还将提示您输入口令以保护生成的软件包密钥库。您可以选择不提供任何口令,但是这样做会导致软件包密钥库不会加密。

以下过程介绍了证书格式正确时,如何使用 pkgadm 命令导入证书。

导入在 PEM 或 DER 编码的 X.509 证书文件中找到的所有证书颁发机构证书。

例如,要导入在 ca.pem 文件中找到的所有证书颁发机构证书,应键入以下内容:

$ pkgadm addcert -k ~/mykeystore -ty ca.pem

输出可能如下所示:

Trusting certificate Subscriber-Persona Not Validated> Trusting certificate Primary Certification Authority Type a Keystore protection Password. Press ENTER for no protection password (not recommended): For Verification: Type a Keystore protection Password. Press ENTER for no protection password (not recommended): Certificate(s) from are now trusted 为了将您的签名密钥导入到软件包密钥库,必须提供别名,供以后签名软件包时使用。如果您要从软件包密钥库中删除密钥,也可能会使用该别名。 例如,要从 sign.pem 文件中导入您的签名密钥,应键入以下内容: $ pkgadm addcert -k ~/mykeystore -n mycert sign.pem 输出可能如下所示: Enter PEM passphrase: Enter Keystore Password: Successfully added Certificate with alias 检验证书是否在软件包密钥库中。 例如,要在密钥库中查看在上一步骤中创建的证书,应键入以下内容: $ pkgadm listcert -k ~/mykeystore

我怎样才能获得SecKeyRef从DER / PEM文件

最近几天折腾了一下如何在iOS上使用RSA来加密。iOS上并没有直接的RSA加密API。但是iOS提供了x509的API,而x509是支持RSA加密的。因此,我们可以通过制作自签名的x509证书(由于对安全性要求不高,我们并不需要使用CA认证的证书),再调用x509的相关API来进行加密。接下来记录一下整个流程。

第一步,制作自签名的证书

1.最简单快捷的方法,打开Terminal,使用openssl(Mac OS X自带)生成私钥和自签名的x509证书。

openssl req -x509 -out public_key.der -outform der -new -newkey rsa:1024 -keyout private_key.pem -days 3650

按照命令行的提示输入内容就行了。

几个说明:

public_key.der是输出的自签名的x509证书,即我们要用的。

private_key.pem是输出的私钥,用来解密的,请妥善保管。

rsa:1024这里的1024是密钥长度,1024是比较安全的,如果需要更安全的话,可以用2048,但是加解密代价也会增加。

-days:证书过期时间,一定要加上这个参数,默认的证书过期时间是30天,一般我们不希望证书这么短就过期,所以写上比较合适的天数,例如这里的3650(10年)。

事实上,这一行命令包含了好几个步骤(我研究下面这些步骤的原因是我手头已经由一个private_key.pem私钥了,想直接用这个来生成x509证书,也就是用到了下面的2-3)

1)创建私钥

openssl genrsa -out private_key.pem 1024

2)创建证书请求(按照提示输入信息)

openssl req -new -out cert.csr -key private_key.pem

3)自签署根证书

openssl x509 -req -in cert.csr -out public_key.der -outform der -signkey private_key.pem -days 3650

2.验证证书。把public_key.der拖到xcode中,如果文件没有问题的话,那么就可以直接在xcode中打开,看到证书的各种信息。

第二步,使用public_key.der来进行加密。

1.导入Security.framework。

2.把public_key.der放到mainBundle中(一般直接拖到Xcode就行啦)。

3.从public_key.der读取公钥。

4.加密。

下面是参考代码(只能用于加密长度小于等于116字节的内容,适合于对密码进行加密。使用了ARC,不过还是要注意部分资源需要使用CFRealse来释放)

RSA.h

//

// RSA.h

//

#import @interface RSA : NSObject { SecKeyRef publicKey; SecCertificateRef certificate; SecPolicyRef policy; SecTrustRef trust; size_t maxPlainLen; } – (NSData *) encryptWithData:(NSData *)content; – (NSData *) encryptWithString:(NSString *)content; @end RSA.m // // RSA.m // #import “RSA.h” @implementation RSA – (id)init { self = [super init]; NSString *publicKeyPath = [[NSBundle mainBundle] pathForResource:@”public_key” ofType:@”der”]; if (publicKeyPath == nil) { NSLog(@”Can not find pub.der”); return nil; } NSDate *publicKeyFileContent = [NSData dataWithContentsOfFile:publicKeyPath]; if (publicKeyFileContent == nil) { NSLog(@”Can not read from pub.der”); return nil; } certificate = SecCertificateCreateWithData(kCFAllocatorDefault, ( __bridge CFDataRef)publicKeyFileContent); if (certificate == nil) { NSLog(@”Can not read certificate from pub.der”); return nil; } policy = SecPolicyCreateBasicX509(); OSStatus returnCode = SecTrustCreateWithCertificates(certificate, policy, &trust); if (returnCode != 0) { NSLog(@”SecTrustCreateWithCertificates fail. Error Code: %ld”, returnCode); return nil; } SecTrustResultType trustResultType; returnCode = SecTrustEvaluate(trust, &trustResultType); if (returnCode != 0) { NSLog(@”SecTrustEvaluate fail. Error Code: %ld”, returnCode); return nil; } publicKey = SecTrustCopyPublicKey(trust); if (publicKey == nil) { NSLog(@”SecTrustCopyPublicKey fail”); return nil; } maxPlainLen = SecKeyGetBlockSize(publicKey) – 12; return self; } – (NSData *) encryptWithData:(NSData *)content { size_t plainLen = [content length]; if (plainLen > maxPlainLen) { NSLog(@”content(%ld) is too long, must < %ld", plainLen, maxPlainLen); return nil; } void *plain = malloc(plainLen); [content getBytes:plain length:plainLen]; size_t cipherLen = 128; // 当前RSA的密钥长度是128字节 void *cipher = malloc(cipherLen); OSStatus returnCode = SecKeyEncrypt(publicKey, kSecPaddingPKCS1, plain, plainLen, cipher, &cipherLen); NSData *result = nil; if (returnCode != 0) { NSLog(@"SecKeyEncrypt fail. Error Code: %ld", returnCode); } else { result = [NSData dataWithBytes:cipher length:cipherLen]; } free(plain); free(cipher); return result; } - (NSData *) encryptWithString:(NSString *)content { return [self encryptWithData:[content dataUsingEncoding:NSUTF8StringEncoding]]; } - (void)dealloc{ CFRelease(certificate); CFRelease(trust); CFRelease(policy); CFRelease(publicKey); } @end 使用方法: RSA *rsa = [[RSA alloc] init]; if (rsa != nil) { NSLog(@"%@",[rsa encryptWithString:@"test"]); } else { NSLog(@"init rsa error"); } RSA.h // // RSA.h // #import @interface RSA : NSObject { SecKeyRef publicKey; SecCertificateRef certificate; SecPolicyRef policy; SecTrustRef trust; size_t maxPlainLen; } - (NSData *) encryptWithData:(NSData *)content; - (NSData *) encryptWithString:(NSString *)content; @end RSA.m // // RSA.m // #import "RSA.h" @implementation RSA - (id)init { self = [super init]; NSString *publicKeyPath = [[NSBundle mainBundle] pathForResource:@"public_key" ofType:@"der"]; if (publicKeyPath == nil) { NSLog(@"Can not find pub.der"); return nil; } NSDate *publicKeyFileContent = [NSData dataWithContentsOfFile:publicKeyPath]; if (publicKeyFileContent == nil) { NSLog(@"Can not read from pub.der"); return nil; } certificate = SecCertificateCreateWithData(kCFAllocatorDefault, ( __bridge CFDataRef)publicKeyFileContent); if (certificate == nil) { NSLog(@"Can not read certificate from pub.der"); return nil; } policy = SecPolicyCreateBasicX509(); OSStatus returnCode = SecTrustCreateWithCertificates(certificate, policy, &trust); if (returnCode != 0) { NSLog(@"SecTrustCreateWithCertificates fail. Error Code: %ld", returnCode); return nil; } SecTrustResultType trustResultType; returnCode = SecTrustEvaluate(trust, &trustResultType); if (returnCode != 0) { NSLog(@"SecTrustEvaluate fail. Error Code: %ld", returnCode); return nil; } publicKey = SecTrustCopyPublicKey(trust); if (publicKey == nil) { NSLog(@"SecTrustCopyPublicKey fail"); return nil; } maxPlainLen = SecKeyGetBlockSize(publicKey) - 12; return self; } - (NSData *) encryptWithData:(NSData *)content { size_t plainLen = [content length]; if (plainLen > maxPlainLen) { NSLog(@”content(%ld) is too long, must < %ld", plainLen, maxPlainLen); return nil; } void *plain = malloc(plainLen); [content getBytes:plain length:plainLen]; size_t cipherLen = 128; // 当前RSA的密钥长度是128字节 void *cipher = malloc(cipherLen); OSStatus returnCode = SecKeyEncrypt(publicKey, kSecPaddingPKCS1, plain, plainLen, cipher, &cipherLen); NSData *result = nil; if (returnCode != 0) { NSLog(@"SecKeyEncrypt fail. Error Code: %ld", returnCode); } else { result = [NSData dataWithBytes:cipher length:cipherLen]; } free(plain); free(cipher); return result; } - (NSData *) encryptWithString:(NSString *)content { return [self encryptWithData:[content dataUsingEncoding:NSUTF8StringEncoding]]; } - (void)dealloc{ CFRelease(certificate); CFRelease(trust); CFRelease(policy); CFRelease(publicKey); } @end 使用方法: RSA *rsa = [[RSA alloc] init]; if (rsa != nil) { NSLog(@"%@",[rsa encryptWithString:@"test"]); } else { NSLog(@"init rsa error"); }

win7加密文件证书导出 win7怎么导出软件证书

导入证书和私钥

1.通过单击「开始」按钮 ,在运行中键入 certmgr.msc,然后按 Enter,打开“证书管理器”。‌ 如果系统提示您输入管理员密码或进行确认,请键入该密码或提供确认。

2.单击要导入证书的目标文件夹,单击“操作”菜单,指向“所有任务”,然后单击“导入”。

3.单击“下一步”,然后按照说明操作。

注意

如果使用证书导入向导时单击“浏览”来搜索证书,请注意,默认情况下“打开”对话框仅显示 X.509 证书。如果要导入其他类型的证书,请选择要在“打开”对话框中导入的证书类型。

导出证书和私钥

1.通过单击「开始」按钮 ,在运行中键入 certmgr.msc,然后按 Enter,打开“证书管理器”。‌ 如果系统提示您输入管理员密码或进行确认,请键入该密码或提供确认。

2.右键单击要导出的证书,指向“所有任务”,然后单击“导出”。

3.在证书导出向导中,单击“下一步”。

4.如果要在其他计算机上使用此证书,请单击“是,导出私钥”;否则,单击“不,不要导出私钥”,然后单击“下一步”。(只有将私钥标记为可导出且可以访问它时才会显示该选项。)

5.单击要使用的格式,然后单击“下一步”。

注意

根据要使用证书的方式选择要使用的格式。对于带有私钥的证书,请使用个人信息交换格式。如果要将一个文件中的多个证书从一台计算机移到另一台计算机,请使用加密消息语法标准。如果需要在多个操作系统上使用证书,请使用 DER 编码的二进制 X.509 格式。

6.如果选择导出私钥,请键入要用于加密密钥的密码,确认该密码,然后单击“下一步”。

7.导出过程会创建一个用于存储证书的文件。输入该文件的名称和位置(包括完整路径),或者单击“浏览”,导航到其位置,然后输入文件名。

8.单击“完成”。

SSL中,公钥,私钥,证书的后缀名都是些啥

1_root_bundle.crt是根证书链(公钥) 2_ domainname.com.key为私钥 其中:证书公钥、私钥文件一般以域名命名;证书后缀名crt和cer

电子签名P7级代表什么

P7是一种签名格式:

x509是数字证书的规范,P7和P12是两种封装形式。比如说同样的电影,有的是avi格式,有的是mpg,大概就这个意思。

P7一般是把证书分成两个文件,一个公钥一个私钥,有PEM和DER两种编码方式。PEM比较多见,就是纯文本的,P7一般是分发公钥用,看到的就是一串可见字符串,扩展名经常是.crt,.cer,.key等。DER是二进制编码。

P12是把证书压成一个文件,.pfx 。主要是考虑分发证书,私钥是要绝对保密的,不能随便以文本方式散播。所以P7格式不适合分发。.pfx中可以加密码保护,所以相对安全些。

在实践中要中,用户证书都是放在USB Key中分发,服务器证书经常还是以文件方式分发。服务器证书和用户证书,都是X509证书,就是里面的属性有区别。

更多电子签名知识看参考wosigndoc电子签名平台或者wosign数字证书网。

如何查看证书的16进制der编码,及证书的各个域der格式

证书一般都是x.509格式的证书,然后经过DER编码,DER是TLV编码,然后再经过base64编码后存储的。

正确的方法,应该是,把证书文件,用binary方式,传送到linux下,然后用linux中的base64来进行文件解 码。

命令如下:base64

-d -i ca.crt > crt.hex

-d的命令是,然后-i是–ignore-garbage

When decoding, ignore non-alphabet characters.

Decoding

require compliant input by default, use –ignore-garbage to

attempt to

recover from non-alphabet characters (such as newlines) in

the encoded

stream.

然后再用vim打开crt.hex,这时候再转换成16进制,就可以查看到正常的证书16进制的DER编码了。

农行证书问题

导出后证书文件的扩展名为.pfx才对,如是.cer,则这个导出的证书文件的内容不全,不含私钥。因此.cer文件导入后形成的证书因不含私钥而不可用。

形成这种问题的原因有两种情形,

一、导出证书时没有选择连同私钥一同导出,因此形成了.cer文件。

二、这个证书的导出文件是一个被二次导出的文件,即证书下载成功后,做过证书的导出,启动了强私钥保护。形成了.pfx的文件,当这个.pfx的文件被导入电脑时,为了安全,其中“标志此私钥是可导出的”这一项没有勾选(系统默认值),证书导入后,再被导出时,“连同私钥一同导出”是不可选的,因此导出的证书不含私钥的,就形成了.cer的文件。

你之所以没有找到,是因为.cer的文件导入后不在证书的“个人”选项卡下,而是在“其他人”的选项卡下。

如何将ASCII编码RSA公钥转换为publickey对象

我不知道你所指的 ASCII 编码的 RSA 公钥具体是什么?

下面这段代码使用 DER 或者 PEM 编码的 X.509 格式证书都可以获得公钥。

Java code?

import java.io.FileInputStream;

import java.security.PublicKey;

import java.security.cert.Certificate;

import java.security.cert.CertificateFactory;

public class Cert {

public static void main(String[] args) throws Exception {

CertificateFactory factory = CertificateFactory.getInstance(“X.509”);

Certificate cert = factory.generateCertificate(new FileInputStream(“e:/security/test.cert.pem”));

PublicKey pubKey = cert.getPublicKey();

}

}