OpenSSL中crypto的简单应用(命令篇)

本文介绍了OpenSSL中crypto库的应用,详细阐述了如何使用OpenSSL命令行工具进行RSA密钥生成、公钥私钥互相转换、加密解密操作,并探讨了不同格式的RSA密钥处理。此外,还提到了对称加密算法Blowfish的使用,以及curl命令在SSL连接中的证书使用。
摘要由CSDN通过智能技术生成

2014-11-19 wcdj


OpenSSL中crypto的简单应用

author:gerry

目录

一些命令...1

一些问题...3

一些测试...4

 

 

The OpenSSL crypto library implements awide range of cryptographic algorithms used in various Internet standards. Theservices provided by this library are used by the OpenSSL implementations ofSSL, TLS and S/MIME, and they have also been used to implement SSH, OpenPGP,and other cryptographic standards.

 

libcrypto consists of a number of sub-libraries that implement the individual algorithms.
The functionality includes symmetric encryption, public key cryptography and key agreement, certificate handling, cryptographic hash functions and a cryptographic pseudo-random number generator.

 

https://www.openssl.org/docs/crypto/crypto.html

https://www.openssl.org/docs/crypto/rsa.html#

 

一些命令

生成RSA私钥

./openssl genrsa -out privatekey.pem 1024

从RSA私钥导出公钥

./openssl rsa -in privatekey.pem -outpublic.pem -outform PEM -pubout

使用RSA公钥加密对数据进行加密

./openssl rsautl -encrypt -inkey public.pem-pubin -in file.txt -out file.ssl

使用RSA私钥对公钥加密的数据解密

./openssl rsautl -decrypt -inkeyprivatekey.pem -in file.ssl -out decrypted.txt

在终端打印输出RSA私钥的结构信息

./openssl rsa -in privatekey.pem -text-noout

 

产生一个随机对称加密算法密钥

dd if=/dev/random of=secretkey bs=16count=1

使用对称加密算法对数据进行加密

./openssl enc -blowfish -pass file:secretkey-in file.txt -out file.bf

使用对称加密算法对数据进行解密

./openssl enc -d -blowfish -passfile:secretkey -in file.bf -out decrypt.bf

 

官方关于rsa命令的帮助页面也提供了一些EXAMPLES。

https://www.openssl.org/docs/apps/rsa.html#

 

 

备注:

更多关于命令的帮助可以参考:manopenssl or http://www.openssl.org/docs/apps/rsa.html

更多关于RSA算法可以参考:RFC 2437 - PKCS #1: RSACryptography Specifications Version 2.0 - rfc2http://tools.ietf.org/pdf/rfc2437.pdf

 

SYNOPSIS(命令的语法)

openssl command [ command_opts ] [command_args ]

 

COMMAND(常用的命令)

genrsa   Generation of RSA Private Key. Superceded by genpkey.

rsa      RSA key management.

rsautl   RSA utility for signing, verification, encryption, and decryption.Superseded by  pkeyutl

enc      Encoding with Ciphers.

 

COMMAND OPTIONS(常用的命令选项)

-pubin
by default a private key is read from the input file: with this option a publickey is read instead.
-pubout
by default a private key is output: with this option a public key will beoutput instead. This option is automatically set if the input is a public key.
-inform DER|NET|PEM
This specifies the input format. The DER option uses an ASN1 DER encoded formcompatible with the PKCS#1 RSAPrivateKey or SubjectPublicKeyInfo format. ThePEM

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值