crypto7.0移植筆記
Crypto移植筆記
2018.06.12 許靜
1. 環境: vs2017, crypto7.0
2. 修改程式碼,使編譯通過。測試crylib專案。
無法開啟原始檔stdio.h, stddef.h,stdlib.h等檔案, 在包含目錄中新增:
C:\Program Files(x86)\Windows Kits\10\Include\10.0.16299.0\ucrt
注意10.0.16299.0版本是否存在本機目錄下。
“找不到Windows SDK版本8.1. 請安裝所需的版本的Windows SDK或者在專案屬性頁中或通過右鍵單擊解決方案並選擇“重定解決方案目標”來更改SDK版本”。更改一下,不出現錯誤。
3. 新增cryptlib.lib和所有.h檔案。
4. 屬性->c/c++->程式碼生成->執行庫 多執行緒除錯。
出錯。
#error指令:Please use the /MD switch for _AFXDLL builds.
原因:將MFC設定成在共享dll中使用MFC.
解決方案:屬性->常規->MFC的使用->在靜態庫中使用MFC.
5. 原始檔
#ifndef __RSA_MAIN_H__
#define __RSA_MAIN_H__
#include <iostream>
#include <string>
#define _GEN_RSA 1
#if !_GEN_RSA
#define _SPE_RSA 1
#endif
class RSA_C {
public:
RSA_C(void);
~RSA_C(void);
std::string PubEn(const char* message);
std::string PriDe(const char* chiphtertext);
void GenerateRSAKey(unsigned int keyLength, const char *privFilename, const char *pubFilename, const char *seed);
private:
unsigned int keyLen;
char *privFilename;
char *pubFilename;
char *seed;
/*
#if _SPE_RSA
RSA::PrivateKey k1;
RSA::PublicKey k2;
AutoSeededRandomPool rnd;
#endif
*/
};
extern RSA_C g_RSA_App;
#endif
- #include "RSA_main.h"
- #include "rsa.h"
- #include "randpool.h"
- #include "hex.h"
- #include "files.h"
- #include "cryptlib.h"
- #include "queue.h"
- #include "filters.h"
- #include "osrng.h"
- #include <stdexcept>
- using std::runtime_error;
- using namespace CryptoPP;
- #pragma comment(lib, "cryptlib.lib")
- RSA_C g_RSA_App;
- #if _GEN_RSA
- static std::string RSADecryptString(const char *privFilename, const char *ciphertext);
- static std::string RSAEncryptString(const char *pubFilename, const char *seed, const char *message);
- static RandomPool& GlobalRNG(void);
- void Encode(const std::string& filename, const BufferedTransformation& bt);
- #endif
- #if _SPE_RSA
- void Encode(const std::string& filename, const BufferedTransformation& bt);
- void Decode(const std::string& filename, BufferedTransformation& bt);
- #endif
- #if _SPE_RSA
- RSA::PrivateKey k1;
- RSA::PublicKey k2;
- AutoSeededRandomPool rnd;
- #endif
- RSA_C::RSA_C(void)
- {
- privFilename = new char[1024];
- pubFilename = new char[1024];
- seed = new char[1024];
- }
- RSA_C::~RSA_C()
- {
- delete privFilename;
- delete pubFilename;
- delete seed;
- }
- std::string RSA_C::PubEn(const char* message)
- {
- std::string enText = "";
- #if _GEN_RSA
- std::cout << "origin text:" << message << '\n';
- enText = RSAEncryptString(pubFilename, seed, message);
- std::cout << "Encrypted Text:" << enText << '\n';
- #endif
- #if _SPE_RSA
- RSAES_OAEP_SHA_Encryptor e(k2);
- StringSource(message, true, new PK_EncryptorFilter(rnd,e, new StringSink(enText)));
- #endif
- return enText;
- }
- std::string RSA_C::PriDe(const char* chiphtertext)
- {
- std::string deText = "";
- #if _GEN_RSA
- std::cout << "Encryped text:" << chiphtertext << '\n';
- deText = RSADecryptString(privFilename, chiphtertext);
- std::cout << "Decrypted Text:" << deText << '\n';
- #endif
- #if _SPE_RSA
- RSAES_OAEP_SHA_Decryptor d(k1);
- StringSource(chiphtertext, true, new PK_DecryptorFilter(rnd, d, new StringSink(deText)));
- #endif
- return deText;
- }
- #if _GEN_RSA
- static RandomPool& GlobalRNG(void)
- {
- static RandomPool randomPool;
- return randomPool;
- }
- #endif
- #if _SPE_RSA
- void EncodePrivateKey(const std::string& filename, const RSA::PrivateKey& key)
- {
- // http://www.cryptopp.com/docs/ref/class_byte_queue.html
- ByteQueue queue;
- key.DEREncodePrivateKey(queue);
- Encode(filename, queue);
- }
- void EncodePublicKey(const std::string& filename, const RSA::PublicKey& key)
- {
- // http://www.cryptopp.com/docs/ref/class_byte_queue.html
- ByteQueue queue;
- key.DEREncodePublicKey(queue);
- Encode(filename, queue);
- }
- void Encode(const std::string& filename, const BufferedTransformation& bt)
- {
- // http://www.cryptopp.com/docs/ref/class_file_sink.html
- FileSink file(filename.c_str());
- bt.CopyTo(file);
- file.MessageEnd();
- }
- void DecodePrivatekey(const std::string& filename, RSA::PrivateKey& key)
- {
- ByteQueue queue;
- Decode(filename, queue);
- key.BERDecodePrivateKey(queue,
相關推薦
crypto7.0移植筆記
Crypto移植筆記 2018.06.12 許靜 1. 環境: vs2017, crypto7.0 2. 修改程式碼,使編譯通過。測試crylib專案
[RK3288][Android6.0] 移植筆記 --- 13.3寸eDP顯示屏新增
Platform: RK3288 OS: Android 6.0 Kernel: 3.10.92 不得不說從 RGB -> LVDS -> MIPI -> eDP 一路過來,現在的
[RK3288][Android6.0] 移植筆記 --- 韌體無法下載到eMMC除錯
Platform: ROCKCHIP OS: Android 6.0 Kernel: 3.10.92 現象: 按照參考設計畫的空板子使用AndroidTool下載images提示準備IDB失敗. An
ECMAScript 6.0 學習筆記
企業 編寫 lan 語言 http targe 程序 blank es6 ECMAScript 6入門 1、ECMAScript 6.0(也就是ES2015 以下簡稱 ES6)是 JavaScript 語言的下一代標準,已經在2015年6月正式發布了。它的目標,是使得 J
thphp5.0學習筆記(一)
mic tel 序號 app clas world char p s 庫類 1.目錄結構: 其中thinkphp子目錄是框架核心目錄 thinkphp結構: 2.入口文件 默認自帶的入口文件位於public/index.php 應用目錄為application,其結構
thinkphp5.0學習筆記(二)API後臺處理與命名空間
mac code 輸入 -1 pub 基礎 select() color 第一個 命名空間 先來看命名空間吧; 命名空間是學習TP的基礎, <?php namespace app\lian\c1; class yi{ public $obj = "這是第一個
thinkphp5.0學習筆記(三)獲取信息,變量,綁定參數
名稱 自動識別 參數順序 query images 報錯 oca nds arc 1.構造函數: 控制器類必須繼承了\think\Controller類,才能使用: 方法_initialize 代碼: <?php namespace app\lian\control
磁盤陣列raid0,raid1,raid5,raid0-1,raid1-0學習筆記
raid0 raid5 raid1 磁盤陣列 磁盤陣列RAID ,REDUNDANTARRAYS OD INDEPENSIVE DISKS ,容錯廉價磁盤陣列,可以通過一些技術將多個較小的磁盤整合為一個較大的磁盤設備,而這個較大的磁盤功能不只是存儲,還具有數據保護的功能。整個RAID的等級不同
vue2.0學習筆記之webpack-simple模板中的路由簡單配置案例
nbsp 主頁 default code vue 兩個文件 new ebp 命名 以下是完成後的目錄結構 案例基礎是已經用 webpack+vue-cli 創建了一個名為 vue_router的工程 , 並安裝了vue-rout
vue2.0學習筆記之自定義組件
2.0 sco ron 自定義組件 定義 temp use 使用 imp step one: 推薦結構 step two: Loading.vue <template> <h3>{{msg}}<
Enterprise Library 5.0 學習筆記
數據 dsm tar ng- one pop releases 緩存 最新版 近期了解了微軟提供的企業開發框架Enterprise Library,眼下最新版本號是6.0,可是不支持FW3.5。所以就學習了5.0的版本號,EL5.0支持FW3.5和4
.net core 2.0學習筆記(四):遷移.net framework 工程到.net core
編譯 its evel hashtable ref 學習筆記 inline null 創建 在遷移.net core的過程中,第一步就是要把.net framework 工程的目標框架改為.net core2.0,但是官網卻沒有提供轉換工具,需要我們自己動手完成了
[dotnetCore2.0]學習筆記之一: ASP.NET Core 升級到2.0
玩耍 後來 razor ons 引用 net ins install 查找 需要升級: 1、SDK2.0 ,需要單獨安裝;https://www.microsoft.com/net/core#windowscmd VS2017 不包含這個SDK;而這個SDK包含了run
一起學ASP.NET Core 2.0學習筆記(一): CentOS下 .net core2 sdk nginx、supervisor、mysql環境搭建
image dev 預覽 def star fig brush rest aspnet 作為.neter,看到.net core 2.0的正式發布,心裏是有點小激動的,迫不及待的體驗了一把,發現速度確實是快了很多,其中也遇到一些小問題,所以整理了一些學習筆記: 閱讀目
.net core 2.0學習筆記(六):Remoting核心類庫RealProxy遷移
ride dispatch 包含 void reflect 既然 splay creat (六) 在學習.net core的過程中,我們已經明確被告知,Remoting將不會被支持。官方的解釋是,.net framework 類型包含了太多的Runtime的內容,是
一起學ASP.NET Core 2.0學習筆記(二): ef core2.0 及mysql provider 、Fluent API相關配置及遷移
upd order rac option 包管理 rtl code create .net core 不得不說微軟的技術叠代還是很快的,上了微軟的船就得跟著她走下去,前文一起學ASP.NET Core 2.0學習筆記(一): CentOS下 .net core2 s
c# 7.0 學習筆記
ole action zed val struct amp ret null int out 可以寫在裏面了 // int result = 0; 不需要寫在外面了 if (!int.TryParse(input, out int result)) { r
react-router 4.0 學習筆記
com alt image div ima cnblogs link 圖片 imp 1、安裝react-router-dom 2、頁面上要使用的時候要引入 import { BrowserRouter as Router, Route, Link } fr
python基本數據類型(二)-python3.0學習筆記
tin 基本數據 abcde 返回 屬性方法 mat sizeof 不可變 map python基本數據類型 序列類型的自帶方法 1.列表的常用方法 2.元祖的常用方法 3.字符串的常用方法 1.列表常用的方法 L.append(obj) #在列表末尾添加新的對
python基本數據類型(一)-python3.0學習筆記
中括號 str 只有一個 most 浮點型 基本 數字類型 shel convert python基本數據類型 1.python課程簡介 2.數據類型 3.序列類型 1.python簡介 1.python是一門編程語言,是一門完全面向對象的編程語言 2.如果對語言進行分類,