[[Open棟梁Project>http://opentouryo.osscons.jp/]] - [[マイクロソフト系技術情報 Wiki>http://techinfoofmicrosofttech.osscons.jp/]]
「[[マイクロソフト系技術情報 Wiki>http://techinfoofmicrosofttech.osscons.jp/]]」は、「[[Open棟梁Project>https://github.com/OpenTouryoProject/]]」,「[[OSSコンソーシアム .NET開発基盤部会>https://www.osscons.jp/dotNetDevelopmentInfrastructure/]]」によって運営されています。

-[[戻る>.NET開発]]
-戻る
--[[.NET開発]]
--[[暗号化アルゴリズム]]

* 目次 [#ba3e104c]
#contents

*概要 [#i831ac3c]
一通り揃っている。
[[暗号化アルゴリズム]]は、一通り揃っている。

-乱数生成~
RNGCryptoServiceProvider

-パスワードからのキー生成~
Rfc2898DeriveBytes

-ハッシュ
--暗号ハッシュ([[様々な用途>https://ja.wikipedia.org/wiki/%E3%83%8F%E3%83%83%E3%82%B7%E3%83%A5%E9%96%A2%E6%95%B0#.E7.94.A8.E9.80.94]]に利用可能)
--キー付きハッシュ([[署名・検証>https://ja.wikipedia.org/wiki/%E6%9A%97%E5%8F%B7%E5%AD%A6%E7%9A%84%E3%83%8F%E3%83%83%E3%82%B7%E3%83%A5%E9%96%A2%E6%95%B0#.E7.94.A8.E9.80.94]]にも利用可能)

-暗号(暗号化・復号化、署名・検証に利用可能)
--秘密鍵暗号方式
--公開鍵暗号方式
--秘密鍵・暗号化
---Aes
---DES
---RC2
---Rijndael
---TripleDES

--公開鍵・暗号化
---RSA
---DSA
---ECDsa

--ハイブリッド・暗号化(キー交換)
---RSA
---ECDiffieHellman

-署名(署名・検証に利用可能)
--公開鍵暗号方式
--RSA
--DSA
--ECDsa

-乱数生成、キー生成
-認証

*Managed、CSP、CNG実装とは? [#fde2f12c]
-Managedで終わる名称のProviderは、.NET実装と思われる(mscorlib.dll)。
-CryptoServiceProvider(CSP)で終わる名称のProviderは、「暗号化サービス プロバイダー (CSP) を使用する」とある(System.Core.dll)。
-Cngで終わる名称のProviderは、PlatformNativeのCryptography Next Generation (CNG) 実装を使用している(System.Core.dll)。
--データの整合性 (MAC)
---HMAC MD5
---HMAC RIPEMD160
---HMAC SHA256
---HMAC SHA384
---HMAC SHA512
---MAC TripleDES 

**参考 [#le45730f]
--データのプライバシー(AEAD)~
については自作が必要。
---3DES-CBC
---AES-CBC
---AES-CTR
---AES-CCM
---AES-GCM ★
---AES-GMAC

***CSP [#n13961a2]
-CryptoAPI Cryptographic Service Providers (Windows)~
https://msdn.microsoft.com/ja-jp/library/windows/desktop/bb931357.aspx
*.NET Frameworkの暗号化Providerの列挙 [#da2f4388]

-Cryptographic API - Wikipedia~
https://ja.wikipedia.org/wiki/Cryptographic_API
**乱数生成、キー生成 [#feec3024]

***CNG [#if785c4b]
***乱数生成 [#z6a6e8e6]
-RNGCryptoServiceProviderを使用して、暗号乱数を生成する。
-Membership.GeneratePasswordも下位でRNGCryptoServiceProviderを使用している。

-CNGとは (Cryptography Next Generation) シーエヌジー: - IT用語辞典バイナリ~
http://www.sophia-it.com/content/Cryptography+Next+Generationax
-参考
--RNGCryptoServiceProvider クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.rngcryptoserviceprovider
--GeneratePassword Method~
http://aspnet.4guysfromrolla.com/demos/GeneratePassword.aspx
---This demo illustrates how to use the code for ASP.NET 2.0's Membership.GeneratePassword() method in ASP.NET 1.x.
--- I 'borrowed' this code from the 2.0 .NET Framework using [[Reflector>http://www.aisto.com/roeder/dotnet/]].

-Cryptography Next Generation~
https://technet.microsoft.com/en-us/library/532ac164-da33-4369-bef0-8f019d5a18b8
***キー生成 [#ta70b091]
-Rfc2898DeriveBytesを使用して、パスワード ベースのキーを生成する。

**どれを使用すべき? [#ub3ba427]
-主に、
--キー付きハッシュ(KeyedHashAlgorithm)
--秘密鍵暗号方式(SymmetricAlgorithm)

-.NET Framework の暗号モデル~
https://msdn.microsoft.com/ja-jp/library/0ss79b2x.aspx
>のキーを生成する(パスワードをそのまま使用しない)。

には、以下のようにある。
-参考
--Rfc2898DeriveBytes クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.rfc2898derivebytes

***最適な実装を選択可能 [#f3be9d35]
**[[ハッシュ化>暗号化アルゴリズム#y6cc34ab]] [#de661712]

-マネージ実装~
.NET Framework をサポートするすべてのプラットフォームで利用可能。~
ただし、マネージ実装はFIPSに認定されておらず、ラッパー クラスよりも低速である場合がある。
***暗号ハッシュ(HashAlgorithm) [#l1894cde]
-HashAlgorithm.Createというファクトリを使用して、~
HashAlgorithm型で扱えば、あまり差異が無く使える。

-CAPI 実装~
CSPラッパー。以前のOSで使用可能だが、開発中止となっている。
-[[Managed、CAPI(CSP)、CNG実装>#fde2f12c]]が揃っている。

-CNG 実装~
CNGラッパー。まさに最新の実装であり、新しい開発が行われる。
-HashAlgorithm クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.hashalgorithm

***アルゴリズムの選択 [#uf945e7e]
-データのプライバシー~
Aes
--MD5 クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.md5
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.md5cng
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.md5cryptoserviceprovider

-データの整合性 
--HMACSHA256
--HMACSHA512
--RIPEMD160 クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.ripemd160
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.ripemd160managed

-デジタル署名 
--ECDsa
--RSA(RS256)
--SHA1 クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.sha1
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.sha1cng
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.sha1cryptoserviceprovider
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.sha1managed

-キー交換
--ECDiffieHellman
--RSA(RS256)
--SHA256 クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.sha256
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.sha256cng
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.sha256cryptoserviceprovider
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.sha256managed

-乱数生成~
RNGCryptoServiceProvider
--SHA384 クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.sha384
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.sha384cng
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.sha384cryptoserviceprovider
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.sha384managed

-パスワードからのキー生成~
Rfc2898DeriveBytes
--SHA512 クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.sha512
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.sha512cng
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.sha512cryptoserviceprovider
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.sha512managed

***CngKey [#v4011842]
-How to use RSA in .NET: RSACryptoServiceProvider vs. RSACng and good practise patterns - Dusted Codes~
https://dusted.codes/how-to-use-rsa-in-dotnet-rsacryptoserviceprovider-vs-rsacng-and-good-practise-patterns
***キー付きハッシュ(KeyedHashAlgorithm) [#x4fe1902]
-KeyedHashAlgorithm.Createというファクトリを使用して、~
KeyedHashAlgorithm型で扱えば、あまり差異が無く使える。~
(ただし、Key指定する場合、個別のコンストラクタを使用する必要がある)

以下の様な違いがあるが、
-[[Managed実装のみで、CAPI(CSP)、CNG実装は無い>#fde2f12c]]。

>RSACngのキーはCngKeyクラスによって管理され、RSACngのコンストラクタに注入できますが、~
RSACryptoServiceProviderは独自のキー操作に結びついています。
-KeyedHashAlgorithm クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.keyedhashalgorithm

[[どちらでも良さそう。>#f3be9d35]]
--HMAC クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.hmac
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.hmacmd5
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.hmacripemd160
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.hmacsha1
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.hmacsha256
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.hmacsha384
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.hmacsha512

***性能 [#h1bd7d6f]
-Measuring the performance of AES implementations in .Net Framework (AesManaged vs AesCryptoServiceProvider) - CodeProject~
https://www.codeproject.com/Tips/844795/Measuring-the-performance-of-AES-implementations-i
--MACTripleDES クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.mactripledes

*.NETの暗号化Providerの列挙 [#da2f4388]
**ハッシュ [#de661712]
**[[秘密鍵・暗号化>暗号化アルゴリズム#u680ecb7]]方式 [#r45cd534]

***暗号ハッシュ(HashAlgorithm) [#l1894cde]
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.hashalgorithm.aspx
***SymmetricAlgorithm [#n8b6a137]

-https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.md5.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.md5cng.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.md5cryptoserviceprovider.aspx
-[[Managed、CAPI(CSP)、CNG実装>#fde2f12c]]の統一性が無い。~
基本、CAPI(CSP)に、CNG・Managed実装が混入しているイメージ。

-https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.ripemd160.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.ripemd160managed.aspx
-SymmetricAlgorithm クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.symmetricalgorithm

-https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.sha1.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.sha1cng.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.sha1cryptoserviceprovider.aspx
--Aes クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.aes
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.aescng
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.aescryptoserviceprovider
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.aesmanaged

-https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.sha256.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.sha256cng.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.sha256cryptoserviceprovider.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.sha256managed.aspx
--DES クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.des
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.descryptoserviceprovider

-https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.sha384.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.sha384cng.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.sha384cryptoserviceprovider.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.sha384managed.aspx
--RC2 クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.rc2
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.rc2cryptoserviceprovider

-https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.sha512.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.sha512cng.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.sha512cryptoserviceprovider.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.sha512managed.aspx
--Rijndael クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.rijndael
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.rijndaelmanaged

***キー付きハッシュ(KeyedHashAlgorithm) [#x4fe1902]
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.keyedhashalgorithm.aspx
--TripleDES クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.tripledes
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.tripledescng
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.tripledescryptoserviceprovider

-System.Security.Cryptography.HMAC~
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.hmac.aspx
**[[公開鍵・暗号化>暗号化アルゴリズム#tfda0d72]]方式 [#q04bc939]

--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.hmacmd5.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.hmacripemd160.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.hmacsha1.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.hmacsha256.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.hmacsha384.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.hmacsha512.aspx
***AsymmetricAlgorithm [#id81129e]

-System.Security.Cryptography.MACTripleDES~
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.mactripledes.aspx
- AsymmetricAlgorithmの内、暗号化・復号化が可能な公開鍵暗号方式は、~
RSAのみ(他のアルゴリズムは、キー交換や署名のみサポート)。

**暗号化 [#pdc25f19]
***秘密鍵暗号方式(SymmetricAlgorithm) [#r45cd534]
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.symmetricalgorithm.aspx
-AsymmetricAlgorithm クラス (System.Security.Cryptography)~
https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.asymmetricalgorithm

-System.Security.Cryptography.Aes~
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.aes.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.aescng.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.aescryptoserviceprovider.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.aesmanaged.aspx
--RSA クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.rsa
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.rsacng
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.rsacryptoserviceprovider
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.rsaopenssl

-System.Security.Cryptography.DES~
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.des.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.descryptoserviceprovider.aspx
**[[ハイブリッド・暗号化(キー交換)>暗号化アルゴリズム#z7306cb4]]方式 [#oeb223a1]

-System.Security.Cryptography.RC2~
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.rc2.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.rc2cryptoserviceprovider.aspx
***AsymmetricKeyExchange [#u0fcff3a]
非対称キー交換フォーマッタ(Formatter)、デフォーマッタ(Deformatter)~
プロバイダをラップして、手続きだけを提供するクラス。

-System.Security.Cryptography.Rijndael~
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.rijndael.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.rijndaelmanaged.aspx
-AsymmetricKeyExchangeFormatter クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.asymmetrickeyexchangeformatter
--RSAOAEPKeyExchangeFormatter クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.rsaoaepkeyexchangeformatter
--RSAPKCS1KeyExchangeFormatter クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.rsapkcs1keyexchangeformatter

-System.Security.Cryptography.TripleDES~
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.tripledes.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.tripledescng.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.tripledescryptoserviceprovider.aspx
-AsymmetricKeyExchangeDeformatter クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.asymmetrickeyexchangedeformatter
--RSAOAEPKeyExchangeDeformatter クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.rsaoaepkeyexchangedeformatter
--RSAPKCS1KeyExchangeDeformatter クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.rsapkcs1keyexchangedeformatter

***公開鍵暗号方式(AsymmetricAlgorithm) [#q04bc939]
AsymmetricAlgorithmの内、暗号化・復号化が可能な公開鍵暗号方式は、RS256(RSA)のみ。
***ECDiffieHellman [#udf3d4f3]
-ECDiffieHellman クラス (System.Security.Cryptography)~
https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.ecdiffiehellman
--https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.ecdiffiehellmancng
--https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.ecdiffiehellmanopenssl

https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.asymmetricalgorithm.aspx
**署名・検証 [#lf5eb161]
[[デジタル署名>暗号化アルゴリズム#leddd7f0]]

-https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.rsacng.aspx
-https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.rsacryptoserviceprovider.aspx
***AsymmetricAlgorithm [#lbe3d6d2]
-RSAだけは、署名・検証だけでなく、暗号化・復号化にも利用可能。
-[[Managed、CAPI(CSP)、CNG実装>#fde2f12c]]が一通り提供されている。~
新しいアルゴリズムは、CNGと[[OpenSSL]]の二択になって行くようにも見える。

**署名・検証(AsymmetricAlgorithm) [#lf5eb161]
署名・検証は、AsymmetricAlgorithmの内の、以下のProviderを使用する。
-AsymmetricAlgorithm クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.asymmetricalgorithm

https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.asymmetricalgorithm.aspx
--RSA クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.rsa
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.rsacng
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.rsacryptoserviceprovider
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.rsaopenssl

-https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.dsacng.aspx
-https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.dsacryptoserviceprovider.aspx
-https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.ecdsacng.aspx
-https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.ecdiffiehellmancng.aspx
--DSA クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.dsa
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.dsacng
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.dsacryptoserviceprovider
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.dsaopenssl

**乱数生成、キー生成 [#feec3024]
--ECDsa クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.ecdsa
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.ecdsacng
---https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.ecdsaopenssl

***乱数生成 [#z6a6e8e6]
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.rngcryptoserviceprovider(v=vs.110).aspx
***AsymmetricSignatureFormatter [#ta0f34c9]
-非対称署名フォーマッタ、デフォーマッタ~
プロバイダをラップして、手続きだけを提供するクラス。

RNGCryptoServiceProviderを使用する。~
Membership.GeneratePasswordも下位でRNGCryptoServiceProviderを使用している。
--AsymmetricSignatureFormatter クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.asymmetricsignatureformatter
---RSAPKCS1SignatureFormatter クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.rsapkcs1signatureformatter
---DSASignatureFormatter クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.dsasignatureformatter

-GeneratePassword Method~
http://aspnet.4guysfromrolla.com/demos/GeneratePassword.aspx
--This demo illustrates how to use the code for ASP.NET 2.0's Membership.GeneratePassword() method in ASP.NET 1.x.
-- I 'borrowed' this code from the 2.0 .NET Framework using [[Reflector>http://www.aisto.com/roeder/dotnet/]].
--AsymmetricSignatureDeformatter クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.asymmetricsignaturedeformatter
---RSAPKCS1SignatureDeformatter クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.rsapkcs1signaturedeformatter
---DSASignatureDeformatter クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.dsasignaturedeformatter

***キー生成 [#ta70b091]
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.rfc2898derivebytes.aspx
**追加可能なプロバイダ [#w62a67fc]

Rfc2898DeriveBytesを使用する。
***Security.Cryptography [#dc18d317]
昨今(、クロスドメイン認証周りの需要でか)、[[日進月歩で追加されている>#ua0d9526]]

主に、
-キー付きハッシュ(KeyedHashAlgorithm)
-秘密鍵暗号方式(SymmetricAlgorithm)
***Security.Cryptography.XML [#hb08dcb9]
[[XML署名・暗号]]

のキーを生成する(パスワードをそのまま使用しない)。
*[[.NET Standard]]の暗号化Providerの列挙 [#db4c9ea1]

**.NET Frameworkからの移植 [#i773c894]
-予想外に、[[CSPやCNGのプロバイダ>#fde2f12c]]も移植されている
-...が、一部含まれないものがある(特にCNG系実装に多い)。
-これら[[CNGのプロバイダの移植>#fde2f12c]]が、今後どう進むか?は不明。

**[[追加のプロバイダ>#u5d4c9e0]] [#b6180c03]

*Managed、CAPI(CSP)、CNG実装とは? [#fde2f12c]
-Managedで終わる名称のProviderは、.NET実装と思われる。

-CryptoServiceProvider (CSP) で終わる名称のProviderは、~
「CryptoAPI Cryptographic Service Providers (CSP ≒ CAPI) 実装と思われる。

-Cryptography Next Generation (CNG) で終わる名称のProviderは、~
CNG Cryptographic Algorithm Providers実装と思われる。

-Understanding Cryptographic Providers | Microsoft Docs~
https://docs.microsoft.com/ja-jp/windows/desktop/SecCertEnroll/understanding-cryptographic-providers

**CAPI (CSP) [#n13961a2]
-CryptoAPI Cryptographic Service Providers | Microsoft Docs~
https://docs.microsoft.com/ja-jp/windows/desktop/SecCertEnroll/cryptoapi-cryptographic-service-providers

-Cryptographic API - Wikipedia~
https://ja.wikipedia.org/wiki/Cryptographic_API

**CNG [#if785c4b]
-CNG系の暗号化プロバイダの秘密鍵、暗号化操作は、~
CNG キー分離サービスは、分離 LSA プロセスでホストされているため、~
CC (Common Criteria)国際標準規格の要求に従ってキープロセス分離を提供する。

-分離 LSA プロセス
--仮想化ベースのセキュリティを使って保護され、OSの他の部分からアクセスできない。
--CNGプロバイダを使用するプロセスは、[[RPC]]を使って分離 LSA プロセスと通信する。

***アルゴリズム [#z76e4427]
-MD5	

-Sha1	
-Sha256	
-Sha384	
-Sha512

-Rsa	

-ECDsa	
--ECDsaP256	
--ECDsaP384	
--ECDsaP521	

-ECDiffieHellman	
--ECDiffieHellmanP256	
--ECDiffieHellmanP384	
--ECDiffieHellmanP521	

***参考 [#jf513bd9]
-Cryptography Next Generation~
https://technet.microsoft.com/en-us/library/532ac164-da33-4369-bef0-8f019d5a18b8
-CNGとは (Cryptography Next Generation) シーエヌジー: - IT用語辞典バイナリ~
http://www.sophia-it.com/content/Cryptography+Next+Generationax
-CNG Key Isolation: Windows 7 不要なサービスを無効&停止!~
http://windows7service.spinse.net/category/10277691-1.html

-How to use RSA in .NET: RSACryptoServiceProvider vs. RSACng and good practise patterns - Dusted Codes~
https://dusted.codes/how-to-use-rsa-in-dotnet-rsacryptoserviceprovider-vs-rsacng-and-good-practise-patterns
--RSACryptoServiceProviderは独自のキー操作に結びついている。
--RSACngのキーはCngKeyクラスによって管理され、コンストラクタに注入できる。

-Microsoft Docs

--Algorithm
---CNG Cryptographic Algorithm Providers~
https://docs.microsoft.com/ja-jp/windows/desktop/SecCertEnroll/cng-cryptographic-algorithm-providers
---CngAlgorithm クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.cngalgorithm

--Key
---CNG Key Storage Providers~
https://docs.microsoft.com/ja-jp/windows/desktop/SecCertEnroll/cng-key-storage-providers
---CngKey クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.cngkey

*[[Managed、CSP、CNG>#fde2f12c]]、OpenSSLの選択肢 [#ub3ba427]

-.NET Framework の暗号モデル | Microsoft Docs~
https://docs.microsoft.com/ja-jp/dotnet/standard/security/cryptography-model

には、以下のようにある。

***最適な実装を選択可能 [#f3be9d35]

-マネージ実装~
.NET Framework をサポートするすべてのプラットフォームで利用可能。~
ただし、マネージ実装はFIPSに認定されておらず、ラッパー クラスよりも低速である場合がある。

-CAPI 実装~
CSPラッパー。以前のOSで使用可能だが、開発中止となっている。

-CNG 実装~
CNGラッパー。まさに最新の実装であり、新しい開発が行われる。

***.NET Core、Linux [#s0c207f4]
-選択と言うより、~
プラットフォームによって限定的になるもよう。

-例えば、X.509 を使用した際に取得できるRSAプロバイダが、
--.NET FrameworkではRSACsp
--.NET Core on WindowsではRSACng
--.NET Core on Linuxでは、RSAOpenSsl

>になることなどを観測した。

-この辺りは、プラットフォーム依存が強いので、~
クロスプラットフォーム対応は難しい部分がありそう。

-ただし、バージョンが上がるにつれて、~
[[着実に実装の移行・追加が進んでいることを確認できた。>#ua0d9526]]

***性能 [#h1bd7d6f]
-Measuring the performance of AES implementations in .Net Framework~
(AesManaged vs AesCryptoServiceProvider) - CodeProject~
https://www.codeproject.com/Tips/844795/Measuring-the-performance-of-AES-implementations-i

*参考 [#mf5f8a70]

-Programming .NET Security - O'Reilly Media~
http://shop.oreilly.com/product/9780596004422.do

-Visual Studio C#でファイルを暗号化してみる~
https://qiita.com/hibara/items/c9096376b1d7b5c8e2ae

-How to use RSA in .NET:~
RSACryptoServiceProvider vs. RSACng and good practise patterns - Dusted Codes~
https://dusted.codes/how-to-use-rsa-in-dotnet-rsacryptoserviceprovider-vs-rsacng-and-good-practise-patterns

**ライブラリ [#u5d4c9e0]

***[[OpenSSL]] [#lddc9143]

***[[BouncyCastle]] [#tc1ee636]

***libsodium [#wc22e484]
-C言語で開発された、クロスプラットフォームの暗号化ライブラリを含む。
-PHPでは、PECLで提供されていたがコアに標準的に組み込まれた等の経緯があるもよう。

-nuget.org
--https://www.nuget.org/packages/libsodium/
--https://www.nuget.org/packages/libsodium-net/

***[[Open 棟梁>https://opentouryo.osscons.jp/index.php?%E6%9A%97%E5%8F%B7%E3%83%BB%E5%BE%A9%E5%8F%B7%E5%8C%96%20%E9%83%A8%E5%93%81]] [#he1630c1]

***参考 [#j0ade641]
-暗号ライブラリの比較 - Wikipedia~
https://ja.wikipedia.org/wiki/%E6%9A%97%E5%8F%B7%E3%83%A9%E3%82%A4%E3%83%96%E3%83%A9%E3%83%AA%E3%81%AE%E6%AF%94%E8%BC%83

**DOBON.NET: VB.NET, C#, 無料ソフトウェア... [#j2316c2c]
http://dobon.net/index.html

-文字列、暗号化: .NET Tips: C#, VB.NET~
http://dobon.net/vb/dotnet/string/index.html

***暗号ハッシュ [#bbfd012a]
-MD5やSHA1などでハッシュ値を計算する: .NET Tips: C#, VB.NET~
http://dobon.net/vb/dotnet/string/md5.html
-ファイルのMD5やSHA1などでハッシュ値を計算する: .NET Tips: C#, VB.NET~
http://dobon.net/vb/dotnet/string/filemd5.html

***秘密鍵暗号方式 [#geb60fa1]
-パスワードで文字列を暗号化する: .NET Tips: C#, VB.NET~
http://dobon.net/vb/dotnet/string/encryptstring.html
-パスワードでファイルを暗号化する: .NET Tips: C#, VB.NET~
http://dobon.net/vb/dotnet/string/encryptfile.html

***公開鍵暗号方式 [#icf617f4]
-公開鍵暗号方法で暗号化する: .NET Tips: C#, VB.NET~
http://dobon.net/vb/dotnet/string/rsaencryption.html

***署名・検証 [#f3bcf75f]
-デジタル署名を作成、検証する: .NET Tips: C#, VB.NET~
http://dobon.net/vb/dotnet/string/digitalsignature.html

***乱数生成、キー生成 [#gb1f54a6]
-乱数を生成する: .NET Tips: C#, VB.NET~
http://dobon.net/vb/dotnet/programing/random.html
-パスワードのようなランダムな文字列を生成する: .NET Tips: C#, VB.NET~
http://dobon.net/vb/dotnet/string/generatepassword.html

**Open棟梁の暗号ラッパー [#he1630c1]
-Managed優先、無ければCSPを使用というポリシーで実装。
-CNG実装への移行は、まだ行っていない。
**OSSコンソーシアム [#x205de1f]
***開発基盤部会 Wiki [#o286d0de]
-[[高度午前 - 技術要素 - セキュリティ - 暗号・認証>https://dotnetdevelopmentinfrastructure.osscons.jp/index.php?%E9%AB%98%E5%BA%A6%E5%8D%88%E5%89%8D%20-%20%E6%8A%80%E8%A1%93%E8%A6%81%E7%B4%A0%20-%20%E3%82%BB%E3%82%AD%E3%83%A5%E3%83%AA%E3%83%86%E3%82%A3%20-%20%E6%9A%97%E5%8F%B7%E3%83%BB%E8%AA%8D%E8%A8%BC]]
-[[SC:対策技術 - 暗号>https://dotnetdevelopmentinfrastructure.osscons.jp/index.php?SC%EF%BC%9A%E5%AF%BE%E7%AD%96%E6%8A%80%E8%A1%93%20-%20%E6%9A%97%E5%8F%B7]]

***暗号ハッシュ [#la4e1baf]
https://github.com/OpenTouryoProject/OpenTouryo/blob/develop/root/programs/C%23/Frameworks/Infrastructure/Public/Util/GetHash.cs#L162
***開発基盤部会 Blog [#ua0d9526]
-.NETの暗号ライブラリが進化している件について。~
https://www.osscons.jp/jo0xhcron-537

-Managed優先、無ければCSPを使用というポリシーで実装。
-Membership.GeneratePasswordを使っている。~
RNGCryptoServiceProviderに変更したい。
--ASP.NETを使ってランダムなパスワードを生成する:CodeZine(コードジン)~
https://codezine.jp/article/detail/238
---GeneratePassword Method~
http://aspnet.4guysfromrolla.com/demos/GeneratePassword.aspx
-JWS (ES256)、JWE (RSAES-OAEP and AES GCM)の実装が完了しました。~
https://www.osscons.jp/joirtdyb5-537/

***キー付きハッシュ [#o0ef5dab]
https://github.com/OpenTouryoProject/OpenTouryo/blob/develop/root/programs/C%23/Frameworks/Infrastructure/Public/Util/GetKeyedHash.cs#L182
----
Tags: [[:.NET開発]], [[:セキュリティ]], [[:暗号化]], [[:証明書]]

-Managedのsuffixが無いが、MSDNではmscorlib.dllとなっているためManaged実装と思われる。

-キーは、Rfc2898DeriveBytesを使用して生成している。

-HMACの実装が不足している。
--HMACSHA1のみ実装
--HMACMD5、HMACRIPEMD160、HMACSHA256、HMACSHA384、HMACSHA512が未実装。

***秘密鍵暗号方式 [#m1c66e75]
https://github.com/OpenTouryoProject/OpenTouryo/blob/develop/root/programs/C%23/Frameworks/Infrastructure/Public/IO/SymmetricCryptography.cs#L430

-AesCryptoServiceProviderが例外的に余分に実装されている。

-キーは、Rfc2898DeriveBytesを使用して生成している。

***公開鍵暗号方式 [#r9036717]
https://github.com/OpenTouryoProject/OpenTouryo/blob/develop/root/programs/C%23/Frameworks/Infrastructure/Public/IO/ASymmetricCryptography.cs

-暗号化・複合化で使用できるのは、RSACryptoServiceProviderのみ。

***署名・検証 [#s1ca647e]
なし。

***乱数生成、キー生成 [#q715ba2e]
なし。

-乱数発生にはRNGCryptoServiceProviderを使ってもイイかもしれない。


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS