RSA library 資訊101乙 F74976324 郭至軒.

Slides:



Advertisements
Similar presentations
Microsoft Word © Automation from Microsoft Access © by Ofer Shimrat for AUGSD MS Office Versions 2000 & 2002.
Advertisements

MatLab API in C++ Christopher Dabney. Purpose MatLab … MatLab … is an interpreted scripting language is an interpreted scripting language conversion to.
RDF Generation and Linking using Open Refine Daniel Vila-Suero
Open XML SDK for Microsoft Office
Linkers and Loaders 1 Linkers & Loaders – A Programmers Perspective.
The Functions and Purposes of Translators Code Generation (Intermediate Code, Optimisation, Final Code), Linkers & Loaders.
GALLERY WALK The purpose of this exercise is to stimulate thinking about what goes on in libraries and information centers so we can generate ideas about.
Working with SharePoint Document Libraries. What are document libraries? Document libraries are collections of files that you can share with team members.
LaMothe DirectX Game in Visual Studio 2008 Matthew Sable.
Console Application Programming Brian Hendricks. Getting Started On the web –New user help adcon.fnal.gov/controls/clib/new_user.html –Library help adcon.fnal.gov/controls/libraries.html.
Free, online, technical courses Take a free online course. Microsoft Virtual Academy.
Namespaces Tonga Institute of Higher Education. Introduction to Namespaces The.Net Framework provides many classes for doing different things  File Input/Output.
ZONG Wen Department of Computer Science and Engineering The Chinese University of Hong Kong
Introduction to C & C++ Lecture 10 – library JJCAO.
An Introduction to Front-end Web Development Tom Perkins.
® IBM Software Group © 2006 IBM Corporation JSF Progress Bar This Learning Module shows how to integrate EGL/JSF functionality into a run-time progress.
ACS Error System APIs: C++ Bogdan Jeram European Southern Observatory July 2005ESO.
5-1 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles.
ACS Component Simulator J. Ibsen European Southern Observatory Garching – January 2007ESO.
Programming with Visual Studio 2005.NET A short review of the process.
Programming with Visual Studio.NET A short review of the process.
Writing a Run Time DLL The application loads the DLL using LoadLibrary() or LoadLibraryEx(). The standard search sequence is used by the operating system.
IBM Software Group | Rational Software © 2003 IBM Corporation 1 iSeries – i5 Machine QSYSWRK SBS QZRCSRVSD (Remote Command Server - daemon) TCP/IP QUSRWRK.
Pocket Code (the app): Pocket Paint (tool for creating images):
Introduction to HTML YLLSS - S3. HTML HyperText Markup Language It uses tags( 標籤 ) to markup a web page A tag is like a label, it is used to present its.
GAM666 – Introduction To Game Programming ● DirectX is implemented as a collection of COM objects ● To use a DirectX program, the user must have the correct.
DOCUMENTATION SECTION GLOBAL DECLARATION SECTION
Talking to Robots Using MS Speech SDK 5.1 in C# Sebastian van Delden USC Upstate
Adding SubtractingMultiplyingDividingMiscellaneous.
What is the purpose of this task? To understand the concept “Labour Market Information” What will you learn from this task? To define what LMI is To identify.
Google C++ Testing Framework Dr. Frank Xu Gannon University.
1 How to Install OpenGL u Software running under Microsoft Windows makes extensive use of "dynamic link libraries." A dynamic link library (DLL) is a set.
Finding the right virtual space. Vendors available
Web Development Tools Milton Acevedo Jerry Jones.
JavaScript 101 Introduction to Programming. Topics What is programming? The common elements found in most programming languages Introduction to JavaScript.
Open project in Microsoft Visual Studio → build program in “Release” mode.
ICT and Health & Safety Lesson 5. Starter – 5 minutes write Lessons Aims in space provided in booklet Lesson Aims: To begin to collect information for.
MTA EXAM HTML5 Application Development Fundamentals.
Nick Application Development for the Universal Windows Platform MOB225.
CS2852 Week 2, Class 2 Today Big-O runtime analysis Linked Lists Muddiest Point Lab Quiz Includes writing a method from ArrayList class (See next slide)
JQuery “write less, do more”. jQuery - Introduction Simply a JavaScript library to simplify JavaScript programming itself Wraps long standard JavaScript.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Introduction Purpose  This training course demonstrates the Project Generator function.
Employee Purchase Experience. Home Use Program 1 Enter work Enter program code Click on “Submit” Country Chooser.
GOOGLE PLAY By William Cook April 14, GOOGLE PLAY Marketplace for apps for android Androids “app store” You must make an account on the developer.
网上报账系统包括以下业务: 日常报销 差旅费报销 借款业务 1. 填写报销内容 2. 选择支付方式 (或冲销借款) 3. 提交预约单 4. 打印预约单并同分类粘 贴好的发票一起送至财务 处 预约报销步骤: 网上报账系统 薪酬发放管理系统 财务查询系统 1.
STEPS FOR EFFECTIVE STUDYING. STUDYING EFFECTIVELY IS A PROCESS, NOT AN EVENT THE PROCESS LEADS TO SUCCESS.
Database (Microsoft Access). Database A database is an organized collection of related data about a specific topic or purpose. Examples of databases include:
1 Microsoft Access Security Warnings Note: This presentation was created with "Access 2002". You might have slightly different warnings with other versions.
SYNOPTIC DISPLAY current status August 13, Abstract Synoptic Display is a Java application for flexible online graphical presentation of data received.
Visual Studio 2017 By Michael Washington
ADK HLK and E/WDK updates for the Windows 10 Fall Creators Update
External Web Services Quick Start Guide
Real time. Real people. Real info. Welcome everyone.
Buy Skin Lightening Cream UK | Everything4you
Questions: Rajiv Nariani
ECIP AAFEPA November 2011.
PRG 421 GUIDE Lessons in Excellence -- prg421guide.com.
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Executing Runtime Checks (For Comp401 and Comp410)
12/1/2018 9:33 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Halloween Assignment Title Slide
English-Language Development
Teaching Computing to GCSE
How to Create a Microsoft Access 2007 Database
Adding with 9’s.
Adding with 10’s.
The visual studio window
Write down 3 things you know about websites.
Adding ____ + 10.
Understanding DLLs and headers, and libs… Jeff Chastine.
Presentation transcript:

RSA library 資訊101乙 F74976324 郭至軒

將介紹Chilkat VC++ Library 此library含有許多類別,其中包括RSA的class

Download http://www.chilkatsoft.com/ 選擇左處的DOWNLOAD 接著往下找,找到符合你IDE的載點,點下去即可下載,這個 library似乎只能在windows上使用 我作業系統為Win Vista,使用Visual Stdio 2008 在這我們選擇Chilkat C/C++ Libraries for VC++ 9.0 / Win32

使用預備工作 打開解壓縮檔 將裡面的include, lib這兩個資料夾解壓縮道專案的資料夾內

解壓縮裡有個LinkSample的資料夾,裡面有連結的範例 以下為他的內容 // LinkSample.cpp : Defines the entry point for the console application. // #include <windows.h> #include <tchar.h> // This example does nothing more than include a number of Chilkat headers // and instantiating objects for the purpose of demonstrating a clean build // and link (i.e. there are no unresolved externals). // If you didn't ready the README.html that is included with the download, // you should probably spend a few minutes reviewing it. It tells what // Chilkat lib should be linked, depending on the "Runtime Library" setting // in your Project Properties --> C++ --> Code Generation settings. // It also tells what additional Microsoft libs need to be added to your // list of link libraries, such as ws2_32.lib, crypt32.lib, etc.

#include ". /include/CkZip. h" #include ". /include/CkFtp2 #include "../include/CkZip.h" #include "../include/CkFtp2.h" #include "../include/CkMailMan.h" #include "../include/CkXml.h" #include "../include/CkPrivateKey.h" #include "../include/CkCompression.h“ ……… ………… ……………

連結library 開啟Visual Stdio 2008 並開啟一個新專案

工具列從專案進去選屬性( Alt + F7 )

打開組態屬性->連結器->輸入

其他相依性裡打上 ws2_32.lib crypt32.lib rpcrt4.lib dnsapi.lib wininet.lib ../libs/ChilkatRelDll.lib

接下來於程式碼中 #include “../include/CkRsa.h” #include “../include/CkString.h” #include <windows.h> #include <tchar.h> 接著即可開始使用此library之功能

宣告 首先就是宣告一個此類別的物件 CkRsa rsa; 所有操作皆在此類別內 他有提供許多類別函式可供使用 宣告一個即可 注意!!此類別無法賦值及複製

RSA類別定義 // CLASS: CkRsa class CkRsa : public CkObject { private: void *m_impl; bool m_utf8; CkRsa(const CkRsa &); CkRsa &operator=(const CkRsa &); unsigned long nextIdx(void); unsigned long m_resultIdx; CkString m_resultString[10];

public: void. getImpl(void) const; CkRsa(void public: void *getImpl(void) const; CkRsa(void *impl); CkRsa(); virtual ~CkRsa(); bool get_Utf8(void) const; void put_Utf8(bool b); bool UnlockComponent(const char *unlockCode); bool SaveLastError(const char *filename); void LastErrorXml(CkString &str); void LastErrorHtml(CkString &str); void LastErrorText(CkString &str); bool DecryptStringENC(const char *str, bool bUsePrivateKey, CkString &out); bool DecryptString(const CkByteData &bData, bool bUsePrivateKey, CkString &out); bool DecryptBytesENC(const char *str, bool bUsePrivateKey, CkByteData &out); bool DecryptBytes(const CkByteData &bData, bool bUsePrivateKey, CkByteData &out); bool EncryptStringENC(const char *str, bool bUsePrivateKey, CkString &out); bool EncryptBytesENC(const CkByteData &bData, bool bUsePrivateKey, CkString &out); bool EncryptString(const char *str, bool bUsePrivateKey, CkByteData &out); bool EncryptBytes(const CkByteData &bData, bool bUsePrivateKey, CkByteData &out);

void get_EncodingMode(CkString &out); void put_EncodingMode(const char void get_EncodingMode(CkString &out); void put_EncodingMode(const char *str); void get_Charset(CkString &out); void put_Charset(const char *str); bool GenerateKey(int numBits); bool ExportPublicKey(CkString &strXml); bool ExportPrivateKey(CkString &strXml); bool ImportPublicKey(const char *strXml); bool ImportPrivateKey(const char *strXml); bool SnkToXml(const char *filename, CkString &strXml); long get_NumBits(void); bool get_OaepPadding(void); void put_OaepPadding(bool newVal); bool get_LittleEndian(void); void put_LittleEndian(bool newVal); bool VerifyStringENC(const char *str, const char *hashAlg, const char *sig); bool VerifyString(const char *str, const char *hashAlg, const CkByteData &sigData); bool VerifyBytesENC(const CkByteData &bData, const char *hashAlg, const char *encodedSig); bool VerifyBytes(const CkByteData &bData, const char *hashAlg, const CkByteData &sigData); const char *signStringENC(const char *str, const char *hashAlg); const char *signBytesENC(const CkByteData &bData, const char *hashAlg);

bool SignStringENC(const char. str, const char bool SignStringENC(const char *str, const char *hashAlg, CkString &out); bool SignBytesENC(const CkByteData &bData, const char *hashAlg, CkString &out); bool SignString(const char *str, const char *hashAlg, CkByteData &out); bool SignBytes(const CkByteData &bData, const char *hashAlg, CkByteData &out); const char *lastErrorText(void); const char *lastErrorXml(void); const char *lastErrorHtml(void); const char *decryptStringENC(const char *str, bool bUsePrivateKey); const char *decryptString(const CkByteData &bData, bool bUsePrivateKey); const char *encryptStringENC(const char *str, bool bUsePrivateKey); const char *encryptBytesENC(const CkByteData &bData, bool bUsePrivateKey); const char *encodingMode(void); const char *charset(void); const char *exportPublicKey(void); const char *exportPrivateKey(void); const char *snkToXml(const char *filename); void get_Version(CkString &str); const char *version(void);

bool OpenSslVerifyBytes(CkByteData &signature, CkByteData &outBytes); bool OpenSslSignBytes(CkByteData &data, CkByteData &outBytes); bool OpenSslSignBytesENC(CkByteData &data, CkString &outStr); const char *openSslSignBytesENC(CkByteData &data); bool OpenSslSignString(const char *str, CkByteData &outBytes); bool OpenSslSignStringENC(const char *str, CkString &outStr); const char *openSslSignStringENC(const char *str); bool OpenSslVerifyBytesENC(const char *str, CkByteData &outBytes); bool OpenSslVerifyString(CkByteData &data, CkString &outStr); const char *openSslVerifyString(CkByteData &data); bool OpenSslVerifyStringENC(const char *str, CkString &outStr); const char *openSslVerifyStringENC(const char *str); bool VerifyPrivateKey(const char *xml); bool VerifyHash(CkByteData &hashBytes, const char *hashAlg, CkByteData &sigBytes); bool VerifyHashENC(const char *encodedHash, const char *hashAlg, const char *encodedSig); bool SignHash(CkByteData &hashBytes, const char *hashAlg, CkByteData &outBytes); bool SignHashENC(const char *encodedHash, const char *hashAlg, CkString &outStr); const char *signHashENC(const char *encodedHash, const char *hashAlg); bool get_VerboseLogging(void); void put_VerboseLogging(bool newVal); };

函式介紹 private成員 bool m_utf8; 此值用以判斷輸入之字串以UTF-8編碼或是以ANSI編碼 當其為true,所有輸入輸出之字串皆以UTF-8編碼,反之,則 為ANSI編碼 CkRsa(const CkRsa &); CkRsa &operator=(const CkRsa &); 此兩個成原函式放於private以至於此class無法進行賦值及複製

public成員 bool get_Utf8(void) const; 查看目前字串編碼狀態 void put_Utf8(bool b); 設定字串編碼狀態,true為UTF-8,false為ANSI bool GenerateKey(int numBits); 產生金鑰,同時產生public key 及 private key,回傳表成功與否,PS. 傳入值 需在512-4096之間 long get_NumBits(void); 回傳目前金鑰位元數 const char *exportPublicKey(void); const char *exportPrivateKey(void); 將存在物件裡的金鑰以一字串型態回傳( 上者為public key 下者為private key ) bool ImportPublicKey(const char *strXml); bool ImportPrivateKey(const char *strXml); 將現有金鑰存入物件內,回傳值表是否成功(上者為public key 下者為private key )

範例 產生一對金鑰 GenerateKey.cpp GenerateKey.exe public key.xml private key.xml 匯入金鑰 KeyImport.cpp KeyImport.exe

bool get_OaepPadding(void); 取得目前OAEP( Optimal Asymmetric Encryption Padding )是否使用, true為有使用,flase則無使用 void put_OaepPadding(bool newVal); 欲使用OAEP則傳入true,否則傳入false const char *lastErrorText(void); const char *lastErrorXml(void); const char *lastErrorHtml(void); 以上皆為回傳最後訊息,僅儲存格式不同 void LastErrorXml(CkString &str); void LastErrorHtml(CkString &str); void LastErrorText(CkString &str); 同樣為記錄最後訊息,但需傳入一CkString之物件來儲存 bool SaveLastError(const char *filename); 將錯誤訊息做記錄,參數為一檔案名稱之字串,回傳值true表示存檔成功, false則表失敗

範例 訊息記錄 LastError.cpp LastError.exe log.txt

void put_EncodingMode(const char *str); 此函式用來決定密文以何種型式儲存,有“hex”, “base64”, “url”, “quoted-printable”四種模式 const char *encodingMode(void); 回傳目前以何種型式儲存密文 void get_EncodingMode(CkString &out); 傳入一CkString物件,以儲存目前密文以何種型式儲存 const char *encryptStringENC(const char *str, bool bUsePrivateKey); 加密明文,第一個參數傳入明文,第二個參數為使用public key 還是 private key,true表使用private key,反之則使用public key, 傳回一個密文的字串,此字串內容為xml檔案 bool EncryptStringENC(const char *str, bool bUsePrivateKey, CkString &out); 同樣為加密,但回傳值表示是否加密成功,加密後密文將存於第 三個參數CkString之物件內

const char *decryptStringENC(const char *str, bool bUsePrivateKey); 解密密文,第一個參數傳入密文,第二個參數為使用public key 還是 private key,true表使用private key,反之則使用 public key,傳回一個明文的字串,此字串內容為xml檔案 bool DecryptStringENC(const char *str, bool bUsePrivateKey, CkString &out); 同樣為解密,但回傳值表示是否解密成功,解密後明文將存於 第三個參數CkString之物件內 void put_Charset(const char *str); 傳入一字串,字串內容為編碼方式(EX.utf-8),則所有明文都 將先轉換為utf-8之編碼,再做加密 const char *charset(void); 取得目前編碼方式,傳回一字串表目前編碼 void get_Charset(CkString &out); 同樣為取得編碼方式,但需傳入一CkString之物件來儲存內容

範例 加密與解密 Encrypt_Decrypt.cpp Encrypt_Decrypt.exe

bool SnkToXml(const char *filename, CkString &strXml); 將.snk檔轉為xml的模式並儲存於一CkString物件 const char *snkToXml(const char *filename); 功能同上一函式,但將轉換結果以字串傳回 const char *signStringENC(const char *str, const char *hashAlg); 製作簽章,第一個參數為欲製作簽章之明文,第二個為使用之 hash演算法(EX.sha-1,md5….),以字串型態回傳簽章,PS. 使用時, 物件內需以匯入私密金鑰 bool VerifyStringENC(const char *str, const char *hashAlg, const char *sig); 驗證簽章,第一個參數為欲驗證之明文,第二個為使用之hash演 算法(EX.sha-1,md5….),第三個為已得到之簽章,回傳值表驗證是 否正確,PS. 使用時物件內需已匯入公開金鑰 此library之許多函式還有位元版,使用方是皆大同小異,就不再 贅述

範例 數位簽章 Sign.cpp Sign.exe

結論 由以上範例可得知,RSA僅僅加密短短的明文,也會產生相當 龐大的密文,因此使用RSA加密整個明文相當耗時且耗空間 此library無法加密中文 此library不僅有RSA之library,還有許多其他library,且欲使 用完整的RSA所有功能,也需熟悉其他library之功能,他許多 類別都是緊緊相扣的