(一) Botan 简介
botan官网:http://botan.randombit.net/
Botan 是一个 C++ 的加密算法库,支持 AES, DES, SHA-1, RSA, DSA, Diffie-Hellman 等多种算法,支持 X.509 认证以及CRLs 和 PKCS #10
中文介绍:http://www.oschina.net/p/botan
实现的算法: http://botan.randombit.net/algos.html
————————————————————————————————————————————–
Botan provides a number of different cryptographic algorithms and primitives, including:
Public key cryptography
Encryption algorithms RSA, ElGamal, DLIES (padding schemes OAEP, PKCS #1 v1.5)
Signature algorithms RSA, DSA, ECDSA, GOST 34.10-2001, Nyberg-Rueppel, Rabin-Williams (padding schemes PSS, PKCS #1 v1.5, X9.31)
Key agreement techniques Diffie-Hellman and ECDH
Hash functions
NIST hashes: SHA-1, SHA-224, SHA-256, SHA-384, and SHA-512
RIPE hashes: RIPEMD-160 and RIPEMD-128
SHA-3 candidates Skein-512, Keccak, and Blue Midnight Wish-512
Other common hash functions Whirlpool and Tiger
National standard hashes HAS-160 and GOST 34.11
Obsolete or insecure hashes MD5, MD4, MD2
Non-cryptographic checksums Adler32, CRC24, CRC32
Block ciphers
AES (Rijndael) and AES candidates Serpent, Twofish, MARS, CAST-256, RC6
DES, and variants 3DES and DESX
National/telecom block ciphers SEED, KASUMI, MISTY1, GOST 28147, Skipjack
Other block ciphers including Blowfish, CAST-128, IDEA, Noekeon, TEA, XTEA, RC2, RC5, SAFER-SK, and Square
Block cipher constructions Luby-Rackoff and Lion
Block cipher modes ECB, CBC, CBC/CTS, CFB, OFB, CTR, XTS and authenticated cipher mode EAX
Stream ciphers ARC4, Salsa20/XSalsa20, Turing, and WiderWake4+1
Authentication codes HMAC, CMAC (aka OMAC1), CBC-MAC, ANSI X9.19 DES-MAC, and the protocol-specific SSLv3 authentication code
Public Key Infrastructure
X.509 certificates (including generating new self-signed and CA certs) and CRLs
Certificate path validation
PKCS #10 certificate requests (creation and certificate issue)
Other cryptographic utility functions including
Key derivation functions for passwords: PBKDF1 (PKCS #5 v1.5), PBKDF2 (PKCS #5 v2.0), OpenPGP S2K (RFC 2440)
General key derivation functions KDF1 and KDF2 from IEEE 1363
PRFs from ANSI X9.42, SSL v3.0, TLS v1.0
—————————————————————————————————————————————————————————————————-
(一) Botan 编译
下载:在 botan 官网主页点击如下链接进入下载页:
Getting The Latest Sources
最新稳定版本:1.10.1
上一个稳定版本:1.8.13
Botan的编译需要python支持,某个版本的botan只能在某些版本的python上编译通过。
(1) Linux 下编译
(i) 下载1.8.13源码,http://botan.randombit.net/files/Botan-1.8.13.tgz
解压,查看 configure.py 文件,确定在哪个版本的python下可以编译通过,1.10.1 在python-2.5以上才能编译,1.8.13 在python 2.4 可以编译。
例如 1.8.13 版本的configure.py 文件中这样写到:
Tested with
CPython 2.4, 2.5, 2.6 - OK
Jython 2.5 - Target detection does not work (use --os and --cpu)
CPython 2.3 and earlier are not supported
Has not been tested with IronPython or PyPy
可以看到这个版本在 2.4,2.5,2.6上编译通过,在2.3和之前的版本均不能通过;
我使用的操作系统是 CentOS release 5.5,默认安装的python是2.4版本。
(ii) 编译
步骤如下:
[root@glnode04 Botan-1.8.13]# python configure.py
[root@glnode04 Botan-1.8.13]# make install
命令执行完成之后,botan安装在 /usr/local 目录下:
/usr/local/lib 目录下是库文件,例如:libbotan-1.8.13.so,libbotan.a。
/usr/local/include/botan 目录下是头文件
/usr/local/bin 目录下有可执行文件 botan-config
编写程序时,直接使用 #include <botan/xxx.h>,gcc会自动到 /usr/local/include 中去寻找头文件。
编译时,直接加上 -lbotan,gcc会自动到 /usr/local/lib下查找库。
最后,在/etc/ld.so.conf文件加上/usr/local/lib,然后运行ldconfig,以便在运行时可以找到 botan 的动态链接库文件。
(2) Windows 下编译
Windows 下编译也比较简单,当然,首先必须安装Python。
若使用Visual Studio,强烈建议使用 Visual Studio 的命令行工具编译,如果直接在 dos 命令行编译,要设置很多环境变量,编译还容易出现问题。
(i) 下载1.8.13源码,http://botan.randombit.net/files/Botan-1.8.13.tgz
然后进行解压
(ii) 编译
参考官网编译说明
Building The Library
官网说到:
On MS Windows
If you don’t want to deal with building botan on Windows, check the website; commonly prebuilt Windows binaries with installers are available, especially for stable versions.
You need to have a copy of Python installed, and have both Python and your chosen compiler in your path. Open a command shell (or the SDK shell), and run:
> python configure.py --cc=msvc (or --cc=gcc for MinGW) [--cpu=CPU]
> nmake
> nmake check # optional, but recommended
> nmake install
For Win95 pre OSR2, the cryptoapi_rng module will not work, because CryptoAPI didn’t exist. And all versions of NT4 lack the ToolHelp32 interface, which is how win32_stats does its slow polls, so a version of the library built with that module will not load under NT4. Later versions of Windows support both methods, so this shouldn’t be much of an issue anymore.
By default the install target will be C:\botan; you can modify this with the --prefix option.
When building your applications, all you have to do is tell the compiler to look for both include files and library files in C:\botan, and it will find both. Or you can move them to a place where they will be in the default compiler search paths (consult your documentation and/or local expert for details).
在dos命令行中编译时,会出现如下问题:
cl.exe /MD /Ibuild\include /O2 /EHsc /GR /D_CONSOLE /DBOTAN_DLL=__declspec(dllexport) /nologo /c src\algo_factory\algo_factory.cpp /Fobuild\lib\algo_factory.obj
build\include\botan/exceptn.h(12) : fatal error C1083: 无法打开包括文件:“exception”: No such file or directory
正确编译方法:
打开 Visual Studio 2005 命令提示符,在命令行下执行以上命令, –cc=msvc 表示使用VS的编译器,即 cl
> python configure.py --cc=msvc
> nmake
> nmake check # optional, but recommended
> nmake install
最后编译生成的头文件和库文件位置是:C:\botan.
(iii) 在 VS 中使用 botan
工具 –> 选项 –> 项目和解决方案 –> VC++目录
加入以下内容:
1) Include File: C:\botan\include
2) Library Files:C:\botan
右键项目,属性,选择debug, 链接器,输入,附加依赖项目中填入 botan.lib
今天的文章c++加密解密程序_非对称加密算法有哪些「建议收藏」分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/87108.html