CryptEnumProviders (CryptAPI)

Windows環境で AES と SHA256 を CryptAPI で使用したくなり、調べ始めました。
.NETで簡単にできることも、CryptAPI 単独で実現しようとすると手続きが面倒です。でも時々 Win32 で実現する必要がある場合もあるので、まぁ情報として有意義ではないかと。

まずは CryptEnumProviders() でCSP一覧を取得する方法です。OSによって実装されているCSPに差異があるので重要な情報です。

 

サンプルプログラム一式 ダウンロード(zip形式)

 

[環境]

コンパイラ : VC++2008 sp1, 32bitコンパイル、/MT(d)
OS : Windows7 64bit Proffesional,  

 

[プログラムソース]
#include <windows.h>
#include <WinCrypt.h>
#include <tchar.h>
#include <stdio.h>
#include <stdlib.h>


#define BUF_SIZE        256

int _tmain(int argc, _TCHAR* argv[])
{
    DWORD       cbName = BUF_SIZE;
    DWORD       dwType;
    DWORD       dwIndex;
    TCHAR       pszName[BUF_SIZE]; 

    _tprintf(_T("Enamerate CSP(Cryptographic Service Provider).\n"));
    _tprintf(_T("===================\n"));

    dwIndex = 0;

    while( CryptEnumProviders (
                        dwIndex,        // インデックス番号
                        NULL,           // 予約
                        0,              // 予約
                        &dwType,        // CSPのタイプ
                        pszName,        // CSPの名称
                        &cbName))       // 名称のストリング長
    {
        _tprintf(_T("%2d %s\n"), dwType, pszName);
        dwIndex++;
        cbName = BUF_SIZE;
    }

    _tprintf(_T("===================\n"));
    _tprintf(_T("HIT [enter] KEY !! "));
    getchar();

    return EXIT_SUCCESS;
}

[実行結果]
Enamerate CSP(Cryptographic Service Provider).
===================
 1 Microsoft Base Cryptographic Provider v1.0
13 Microsoft Base DSS and Diffie-Hellman Cryptographic Provider
 3 Microsoft Base DSS Cryptographic Provider
 1 Microsoft Base Smart Card Crypto Provider
18 Microsoft DH SChannel Cryptographic Provider
 1 Microsoft Enhanced Cryptographic Provider v1.0
13 Microsoft Enhanced DSS and Diffie-Hellman Cryptographic Provider
24 Microsoft Enhanced RSA and AES Cryptographic Provider
12 Microsoft RSA SChannel Cryptographic Provider
 1 Microsoft Strong Cryptographic Provider
===================
HIT [enter] KEY !!

 

最初に記載されている値は ProviderType を示す値で、使用できるアルゴリズムを示します。
詳細は CryptEnumProviderTypes.html を参照。

 

 

ライセンス

本ページの情報は、特記無い限り下記 MIT ライセンスで提供されます。

The MIT License (MIT)

  Copyright 2012 Kinoshita Hidetoshi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 


参考

 


 

変更履歴

2023-11-03 - ページデザイン更新
2012-01-28 - 新規作成

 

Programming Items トップページ

プライバシーポリシー