项目作者: kkAyataka

项目描述 :
Header only C++ AES cipher library
高级语言: C++
项目地址: git://github.com/kkAyataka/plusaes.git
创建时间: 2015-08-15T07:47:42Z
项目社区:https://github.com/kkAyataka/plusaes

开源协议:Boost Software License 1.0

下载


plusaes

Header only C++ AES cipher library.

Development Environment

  • Visual Studio 16 2022 (v143)
  • Xcode 14.3 (Apple clang 14.0.3)
  • GCC 4.8.5 (CentOS 7)

Supported block cipher mode

  • ECB
  • CBC
  • GCM
  • CTR

Usage

For example, about AES-CBC 128-bit.
Encrypts by the plusaes::encrypt_cbc and decripts by the plusaes::decrypt_cbc.

You can use convenient functions like plusaes::key_from_string and plusaes::get_padded_encrypted_size.

  1. #include "plusaes/plusaes.hpp"
  2. #include <string>
  3. #include <vector>
  4. int main() {
  5. // AES-CBC 128-bit
  6. // parameters
  7. const std::string raw_data = "Hello, plusaes";
  8. const std::vector<unsigned char> key = plusaes::key_from_string(&"EncryptionKey128"); // 16-char = 128-bit
  9. const unsigned char iv[16] = {
  10. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  11. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  12. };
  13. // encrypt
  14. const unsigned long encrypted_size = plusaes::get_padded_encrypted_size(raw_data.size());
  15. std::vector<unsigned char> encrypted(encrypted_size);
  16. plusaes::encrypt_cbc((unsigned char*)raw_data.data(), raw_data.size(), &key[0], key.size(), &iv, &encrypted[0], encrypted.size(), true);
  17. // fb 7b ae 95 d5 0f c5 6f 43 7d 14 6b 6a 29 15 70
  18. // decrypt
  19. unsigned long padded_size = 0;
  20. std::vector<unsigned char> decrypted(encrypted_size);
  21. plusaes::decrypt_cbc(&encrypted[0], encrypted.size(), &key[0], key.size(), &iv, &decrypted[0], decrypted.size(), &padded_size);
  22. // Hello, plusaes
  23. }

License

Boost Software License