- 追加された行はこの色です。
- 削除された行はこの色です。
「[[マイクロソフト系技術情報 Wiki>http://techinfoofmicrosofttech.osscons.jp/]]」は、「[[Open棟梁Project>https://github.com/OpenTouryoProject/]]」,「[[OSSコンソーシアム .NET開発基盤部会>https://www.osscons.jp/dotNetDevelopmentInfrastructure/]]」によって運営されています。
-戻る
--[[.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
-認証
--データの整合性 (MAC)
---HMAC MD5
---HMAC RIPEMD160
---HMAC SHA256
---HMAC SHA384
---HMAC SHA512
---MAC TripleDES
--データのプライバシー(AEAD)~
については自作が必要。
---3DES-CBC
---AES-CBC
---AES-CTR
---AES-CCM
---AES-GCM ★
---AES-GMAC
*.NET Frameworkの暗号化Providerの列挙 [#da2f4388]
**乱数生成、キー生成 [#feec3024]
***乱数生成 [#z6a6e8e6]
RNGCryptoServiceProvider クラス (System.Security.Cryptography)~
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.rngcryptoserviceprovider.aspx
-RNGCryptoServiceProviderを使用して、暗号乱数を生成する。
-Membership.GeneratePasswordも下位でRNGCryptoServiceProviderを使用している。
RNGCryptoServiceProviderを使用して、暗号乱数を生成する。
Membership.GeneratePasswordも下位でRNGCryptoServiceProviderを使用している。
-GeneratePassword Method~
-参考
--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/]].
---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/]].
***キー生成 [#ta70b091]
Rfc2898DeriveBytes クラス (System.Security.Cryptography)~
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.rfc2898derivebytes.aspx
-Rfc2898DeriveBytesを使用して、パスワード ベースのキーを生成する。
Rfc2898DeriveBytesを使用して、パスワード ベースのキーを生成する。
-主に、
--キー付きハッシュ(KeyedHashAlgorithm)
--秘密鍵暗号方式(SymmetricAlgorithm)
主に、
-キー付きハッシュ(KeyedHashAlgorithm)
-秘密鍵暗号方式(SymmetricAlgorithm)
>のキーを生成する(パスワードをそのまま使用しない)。
のキーを生成する(パスワードをそのまま使用しない)。
-参考
--Rfc2898DeriveBytes クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.rfc2898derivebytes
**ハッシュ [#de661712]
**[[ハッシュ化>暗号化アルゴリズム#y6cc34ab]] [#de661712]
***暗号ハッシュ(HashAlgorithm) [#l1894cde]
HashAlgorithm クラス (System.Security.Cryptography)~
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.hashalgorithm.aspx
-HashAlgorithm.Createというファクトリを使用して、~
HashAlgorithm型で扱えば、あまり差異が無く使える。
-MD5 クラス (System.Security.Cryptography)~
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]]が揃っている。
-RIPEMD160 クラス (System.Security.Cryptography)~
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.ripemd160.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.ripemd160managed.aspx
-HashAlgorithm クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.hashalgorithm
-SHA1 クラス (System.Security.Cryptography)~
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
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.sha1managed.aspx
--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
-SHA256 クラス (System.Security.Cryptography)~
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
--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
-SHA384 クラス (System.Security.Cryptography)~
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
--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
-SHA512 クラス (System.Security.Cryptography)~
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
--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
--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
--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
***キー付きハッシュ(KeyedHashAlgorithm) [#x4fe1902]
suffixが無いが、調べると、
-基本、CSP (System.Security.Cryptography.Algorithms.dll, mscorlib.dll, netstandard.dll)実装、
-HMACRIPEMD160 と MACTripleDES は、mscorlib.dllとなっているためManaged実装と思われる。
-KeyedHashAlgorithm.Createというファクトリを使用して、~
KeyedHashAlgorithm型で扱えば、あまり差異が無く使える。~
(ただし、Key指定する場合、個別のコンストラクタを使用する必要がある)
KeyedHashAlgorithm クラス (System.Security.Cryptography)~
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.keyedhashalgorithm.aspx
-[[Managed実装のみで、CAPI(CSP)、CNG実装は無い>#fde2f12c]]。
-HMAC クラス (System.Security.Cryptography)~
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.hmac.aspx
-KeyedHashAlgorithm クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.keyedhashalgorithm
--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
--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
-MACTripleDES クラス (System.Security.Cryptography)~
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.mactripledes.aspx
--MACTripleDES クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.mactripledes
**秘密鍵暗号方式(SymmetricAlgorithm) [#r45cd534]
**[[秘密鍵・暗号化>暗号化アルゴリズム#u680ecb7]]方式 [#r45cd534]
***SymmetricAlgorithm [#n8b6a137]
SymmetricAlgorithm クラス (System.Security.Cryptography)~
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.symmetricalgorithm.aspx
-Aes クラス (System.Security.Cryptography)~
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
-[[Managed、CAPI(CSP)、CNG実装>#fde2f12c]]の統一性が無い。~
基本、CAPI(CSP)に、CNG・Managed実装が混入しているイメージ。
-DES クラス (System.Security.Cryptography)~
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.des.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.descryptoserviceprovider.aspx
-SymmetricAlgorithm クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.symmetricalgorithm
-RC2 クラス (System.Security.Cryptography)~
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.rc2.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.rc2cryptoserviceprovider.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
-Rijndael クラス (System.Security.Cryptography)~
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.rijndael.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.rijndaelmanaged.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
-TripleDES クラス (System.Security.Cryptography)~
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
--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
**公開鍵暗号方式(AsymmetricAlgorithm) [#q04bc939]
--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
--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
**[[公開鍵・暗号化>暗号化アルゴリズム#tfda0d72]]方式 [#q04bc939]
***AsymmetricAlgorithm [#id81129e]
AsymmetricAlgorithm クラス (System.Security.Cryptography)~
- AsymmetricAlgorithmの内、暗号化・復号化が可能な公開鍵暗号方式は、~
RSAのみ(他のアルゴリズムは、キー交換や署名のみサポート)。
-AsymmetricAlgorithm クラス (System.Security.Cryptography)~
https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.asymmetricalgorithm
-RSA クラス (System.Security.Cryptography)~
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.rsa
--https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.rsacng
--https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.rsacryptoserviceprovider
--https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.rsaopenssl
--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
-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
**[[ハイブリッド・暗号化(キー交換)>暗号化アルゴリズム#z7306cb4]]方式 [#oeb223a1]
※ AsymmetricAlgorithmの内、暗号化・復号化が可能な公開鍵暗号方式は、~
RSAとECDiffieHellmanのみ(他のアルゴリズムは、署名のみサポート)。
***AsymmetricKeyExchange [#u0fcff3a]
非対称キー交換フォーマッタ(Formatter)、デフォーマッタ(Deformatter)~
プロバイダをラップして、手続きだけを提供するクラス。
***AsymmetricKeyExchangeFormatter, Deformatter [#u0fcff3a]
非対称キー交換フォーマッタ、デフォーマッタ
-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
-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) [#lf5eb161]
***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
**署名・検証 [#lf5eb161]
[[デジタル署名>暗号化アルゴリズム#leddd7f0]]
***AsymmetricAlgorithm [#lbe3d6d2]
AsymmetricAlgorithm クラス (System.Security.Cryptography)~
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.asymmetricalgorithm.aspx
-RSAだけは、署名・検証だけでなく、暗号化・復号化にも利用可能。
-[[Managed、CAPI(CSP)、CNG実装>#fde2f12c]]が一通り提供されている。~
新しいアルゴリズムは、CNGと[[OpenSSL]]の二択になって行くようにも見える。
-RSA クラス (System.Security.Cryptography)~
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.rsa.aspx
--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 クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.asymmetricalgorithm
-DSA クラス (System.Security.Cryptography)~
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.dsa.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.dsacng.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.dsacryptoserviceprovider.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
-ECDsa クラス (System.Security.Cryptography)~
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.ecdsa.aspx
--https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.ecdsacng.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
※ なお、RSAだけは、署名・検証だけでなく、暗号化・復号化にも利用可能。
--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
***AsymmetricSignatureFormatter, Deformatter [#ta0f34c9]
非対称署名フォーマッタ、デフォーマッタ
***AsymmetricSignatureFormatter [#ta0f34c9]
-非対称署名フォーマッタ、デフォーマッタ~
プロバイダをラップして、手続きだけを提供するクラス。
-AsymmetricSignatureFormatter クラス (System.Security.Cryptography)~
--AsymmetricSignatureFormatter クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.asymmetricsignatureformatter
--RSAPKCS1SignatureFormatter クラス (System.Security.Cryptography)~
---RSAPKCS1SignatureFormatter クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.rsapkcs1signatureformatter
--DSASignatureFormatter クラス (System.Security.Cryptography)~
---DSASignatureFormatter クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.dsasignatureformatter
-AsymmetricSignatureDeformatter クラス (System.Security.Cryptography)~
--AsymmetricSignatureDeformatter クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.asymmetricsignaturedeformatter
--RSAPKCS1SignatureDeformatter クラス (System.Security.Cryptography)~
---RSAPKCS1SignatureDeformatter クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.rsapkcs1signaturedeformatter
--DSASignatureDeformatter クラス (System.Security.Cryptography)~
---DSASignatureDeformatter クラス (System.Security.Cryptography)~
https://docs.microsoft.com/ja-jp/dotnet/api/system.security.cryptography.dsasignaturedeformatter
**追加のプロバイダ [#w62a67fc]
**追加可能なプロバイダ [#w62a67fc]
***Security.Cryptography [#dc18d317]
-CLR Security - CodePlex Archive~
https://archive.codeplex.com/?p=clrsecurity
昨今(、クロスドメイン認証周りの需要でか)、[[日進月歩で追加されている>#ua0d9526]]
-NuGet Gallery | Security.Cryptography~
https://www.nuget.org/packages/Security.Cryptography/
-clrsecurity/Security.Cryptography/src at master · MicrosoftArchive/clrsecurity~
https://github.com/MicrosoftArchive/clrsecurity/tree/master/Security.Cryptography/src
***Security.Cryptography.XML [#hb08dcb9]
[[XML署名・暗号]]
--AES with CCM or GCM~
以下のクラスは、コメントを読むとAES-CCM or AES-GCMを実装している。
---AuthenticatedSymmetricAlgorithm
>↑(継承)
---AuthenticatedAes, AuthenticatedAesCng
*[[.NET Standard]]の暗号化Providerの列挙 [#db4c9ea1]
**.NET Frameworkからの移植 [#i773c894]
-予想外に、[[CSPやCNGのプロバイダ>#fde2f12c]]も移植されている
-...が、一部含まれないものがある(特にCNG系実装に多い)。
-これら[[CNGのプロバイダの移植>#fde2f12c]]が、今後どう進むか?は不明。
**追加のプロバイダ [#b6180c03]
**[[追加のプロバイダ>#u5d4c9e0]] [#b6180c03]
***OpenSSL [#lddc9143]
-C言語で開発されているため、クロスプラットフォーム。
-SSL・TLSプロトコルのOSSだが、ユーティリティに暗号化ライブラリを含む。
-[[.NET Standard]]では、OpenSSLベースのプロバイダも提供され始めている。~
(.NET Platform Extensions ?の 2.1以上で使用できる模様)
--RSAOpenSsl
--ECDiffieHellmanOpenSsl
*Managed、CAPI(CSP)、CNG実装とは? [#fde2f12c]
-Managedで終わる名称のProviderは、.NET実装と思われる。
-参考
--OpenSSL - Wikipedia~
https://ja.wikipedia.org/wiki/OpenSSL
-CryptoServiceProvider (CSP) で終わる名称のProviderは、~
「CryptoAPI Cryptographic Service Providers (CSP ≒ CAPI) 実装と思われる。
***BouncyCastle [#tc1ee636]
JavaとC#に機能を提供している。
-Cryptography Next Generation (CNG) で終わる名称のProviderは、~
CNG Cryptographic Algorithm Providers実装と思われる。
-参考
--bouncycastle.org~
https://www.bouncycastle.org/
--Bouncy Castle (cryptography) - Wikipedia~
https://en.wikipedia.org/wiki/Bouncy_Castle_(cryptography)
--Bouncy Castle を使ってみる - プログラム日記~
http://a4dosanddos.hatenablog.com/entry/2015/06/30/002123
-Understanding Cryptographic Providers | Microsoft Docs~
https://docs.microsoft.com/ja-jp/windows/desktop/SecCertEnroll/understanding-cryptographic-providers
***libsodium [#wc22e484]
-C言語で開発された、クロスプラットフォームの暗号化ライブラリを含む。
-PHPでは、PECLで提供されていたがコアに標準的に組み込まれた等の経緯があるもよう。
**CAPI (CSP) [#n13961a2]
-CryptoAPI Cryptographic Service Providers | Microsoft Docs~
https://docs.microsoft.com/ja-jp/windows/desktop/SecCertEnroll/cryptoapi-cryptographic-service-providers
***参考 [#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
-Cryptographic API - Wikipedia~
https://ja.wikipedia.org/wiki/Cryptographic_API
*Managed、CAPI(CSP)、CNG実装とは? [#fde2f12c]
-Managedで終わる名称のProviderは、.NET実装と思われる(mscorlib.dll)。
-CryptoServiceProvider (CSP) で終わる名称のProviderは、「CryptoAPI Cryptographic Service Providers (CSP ≒ CAPI) を使用する」とある(System.Core.dll)。
-Cryptography Next Generation (CNG) で終わる名称のProviderは、CNG Cryptographic Algorithm Providersの実装を使用している(System.Core.dll)。
**CNG [#if785c4b]
-CNG系の暗号化プロバイダの秘密鍵、暗号化操作は、~
CNG キー分離サービスは、分離 LSA プロセスでホストされているため、~
CC (Common Criteria)国際標準規格の要求に従ってキープロセス分離を提供する。
**参考 [#le45730f]
-分離 LSA プロセス
--仮想化ベースのセキュリティを使って保護され、OSの他の部分からアクセスできない。
--CNGプロバイダを使用するプロセスは、[[RPC]]を使って分離 LSA プロセスと通信する。
***CAPI (CSP) [#n13961a2]
-CryptoAPI Cryptographic Service Providers (Windows)~
https://msdn.microsoft.com/ja-jp/library/windows/desktop/bb931357.aspx
***アルゴリズム [#z76e4427]
-MD5
-Cryptographic API - Wikipedia~
https://ja.wikipedia.org/wiki/Cryptographic_API
-Sha1
-Sha256
-Sha384
-Sha512
***CNG [#if785c4b]
-Rsa
-CNGとは (Cryptography Next Generation) シーエヌジー: - IT用語辞典バイナリ~
http://www.sophia-it.com/content/Cryptography+Next+Generationax
-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
-CngAlgorithm クラス (System.Security.Cryptography)~
https://msdn.microsoft.com/ja-jp/library/system.security.cryptography.cngalgorithm.aspx
-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クラスによって管理され、コンストラクタに注入できる。
--MD5
--Sha1
--Sha256
--Sha384
--Sha512
--Rsa
--ECDiffieHellman
---ECDiffieHellmanP256
---ECDiffieHellmanP384
---ECDiffieHellmanP521
--ECDsa
---ECDsaP256
---ECDsaP384
---ECDsaP521
-Microsoft Docs
**どれを使用すべき? [#ub3ba427]
--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
-.NET Framework の暗号モデル~
https://msdn.microsoft.com/ja-jp/library/0ss79b2x.aspx
--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ラッパー。まさに最新の実装であり、新しい開発が行われる。
***アルゴリズムの選択 [#uf945e7e]
-データのプライバシー~
Aes
***.NET Core、Linux [#s0c207f4]
-選択と言うより、~
プラットフォームによって限定的になるもよう。
-データの整合性
--HMAC SHA-256
--HMAC SHA-512
-例えば、X.509 を使用した際に取得できるRSAプロバイダが、
--.NET FrameworkではRSACsp
--.NET Core on WindowsではRSACng
--.NET Core on Linuxでは、RSAOpenSsl
-デジタル署名
--ECDsa
--RSA(RS256: RSA SHA-256)
>になることなどを観測した。
-キー交換
--ECDiffieHellman
--RSA(RS256: RSA SHA-256)
-この辺りは、プラットフォーム依存が強いので、~
クロスプラットフォーム対応は難しい部分がありそう。
-乱数生成~
RNGCryptoServiceProvider
-ただし、バージョンが上がるにつれて、~
[[着実に実装の移行・追加が進んでいることを確認できた。>#ua0d9526]]
-パスワードからのキー生成~
Rfc2898DeriveBytes
***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
以下の様な違いがあるもよう。
--RSACryptoServiceProviderは独自のキー操作に結びついている。
--RSACngのキーはCngKeyクラスによって管理され、コンストラクタに注入できる。
[[どちらでも良さそう。>#f3be9d35]]
***性能 [#h1bd7d6f]
-Measuring the performance of AES implementations in .Net Framework (AesManaged vs AesCryptoServiceProvider) - CodeProject~
-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 棟梁 Wiki>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]
**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]]
***開発基盤部会 Blog [#ua0d9526]
-.NETの暗号ライブラリが進化している件について。~
https://www.osscons.jp/jo0xhcron-537
-JWS (ES256)、JWE (RSAES-OAEP and AES GCM)の実装が完了しました。~
https://www.osscons.jp/joirtdyb5-537/
----
Tags: [[:.NET開発]], [[:セキュリティ]], [[:暗号化]], [[:証明書]]