• 大小: 372KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-16
  • 语言: C#
  • 标签: 源代码  

资源简介

C#实现的数字签名算法源代码C#实现的数字签名算法源代码

资源截图

代码片段和文件信息

// CryptoPP.cpp
//
#include “stdafx.h“

#include 
using CryptoPP::DSA;
using CryptoPP::DSA_DER;
using CryptoPP::DSA_P1363;

#include 
using CryptoPP::PrivateKey;
using CryptoPP::PublicKey;

#include 
using CryptoPP::AutoSeededRandomPool;

#include 
using CryptoPP::FileSource;
using CryptoPP::FileSink;
using CryptoPP::StringSource;
using CryptoPP::StringSink;

bool CreateDSAKeys();
bool SignDSAMessage();
bool VerifyDSAMessage();

int main(int argc char* argv[])
{
    CreateDSAKeys();

    SignDSAMessage();

    VerifyDSAMessage();

    return 0;
}

bool CreateDSAKeys()
{
    AutoSeededRandomPool prng;

    try
    {
        // Crypto++ Key Generation
        DSA::Signer signer;        
        PrivateKey& privateKey = signer.AccessPrivateKey();
        privateKey.GenerateRandom( prng );

        DSA::Verifier verifier( signer );
        PublicKey& publicKey = verifier.AccessPublicKey();

        // Crypto++ Save Keys
        privateKey.Save(FileSink(“private.dsa.cpp.key“));
        publicKey.Save(FileSink(“public.dsa.cpp.key“));
    }

    catch( CryptoPP::Exception& ex )
    {
        cerr << “Caught Error:“ << endl;
        cerr << “ “ << ex.what() << endl;

        return false;
    }

    catch( std::exception& ex )
    {
        cerr << “Caught Error:“ << endl;
        cerr << “ “ << ex.what() << endl;

        return false;
    }

    return true;
}


bool VerifyDSAMessage()
{
    try
    {
        //
        // Crypto++ Load the Pubic Key
        //
        DSA::Verifier verifier;
        PublicKey& publicKey = verifier.AccessPublicKey();

        // publicKey.Load(FileSource(“public.dsa.cpp.key“ true));
        // publicKey.Load(FileSource(“public.dsa.java.key“ true));
        publicKey.Load(FileSource(“public.dsa.cs.key“ true));

        //
        // Retrieve the Message and the Signature on Message
        //
        string message signature;

        // C++
        FileSource( “dsa.cpp.msg“ true new StringSink( message ) );
        FileSource( “dsa.cpp.sig“ true new StringSink( signature ) );

        // Java
        // FileSource( “dsa.java.msg“ true new StringSink( message ) );
        // FileSource( “dsa.java.sig“ true new StringSink( signature ) );

        // C#
        // FileSource( “dsa.cs.msg“ true new StringSink( message ) );
        // FileSource( “dsa.cs.sig“ true new StringSink( signature ) );

        //*
        // --- Begin Java Specific Conversion ---

        //
        // Convert: DER -> P1363
        //

        // Java is DER Encoded Sequence.
        // Crypto++ is P1363 format.
        /*
        {            
            // From dsa.h: If toFormat == DSA_P1363
            //   bufferSize must equal publicKey.SignatureLength()
            size_t length = verifier.SignatureLength();

            // A buffer for the conversion
            byt

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     147479  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx.htm

     文件       2413  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\49D920C6-4CF4-49D1-AE77-D5D16BAB8849.jpg

     文件       5434  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\addto.js

     文件        966  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\AddTo_blink.png

     文件        222  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\AddTo_Delicious.png

     文件        940  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\AddTo_Digg.png

     文件        959  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\AddTo_Facebook.png

     文件        974  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\AddTo_Furl.png

     文件       1133  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\AddTo_Google.png

     文件       1054  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\AddTo_Live.png

     文件        642  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\AddTo_MrWong.png

     文件        131  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\AddTo_Newsvine.png

     文件        800  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\AddTo_Reddit.png

     文件        595  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\AddTo_Simpy.png

     文件       1139  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\AddTo_stumbleupon.png

     文件        468  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\AddTo_Technorati.png

     文件        968  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\AddTo_Yahoo.png

     文件        673  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\ajax-loader.gif

     文件       1679  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\bookmark.js

     文件      25959  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\CodeProject.css

     文件        286  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\discuss.gif

     文件        267  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\fave.gif

     文件       7294  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\ForumClassic.css

     文件       1000  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\forum_faq.gif

     文件       1028  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\forum_newmsg.gif

     文件        974  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\forum_search.gif

     文件      20819  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\ga.js

     文件      10100  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\image01.png

     文件      10568  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\image02.png

     文件       9456  2008-05-16 20:08  C#数字签名源码\CryptoInteropSign.aspx_files\image03.png

............此处省略112个文件信息

评论

共有 条评论