forked from dotnet/corefx
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rodriges Hechicero
committed
Oct 25, 2018
1 parent
886552e
commit 895e89f
Showing
4 changed files
with
162 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
src/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/Gost28147.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Internal.Cryptography; | ||
using System.ComponentModel; | ||
|
||
namespace System.Security.Cryptography | ||
{ | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public abstract class Gost28147 : SymmetricAlgorithm | ||
{ | ||
protected Gost28147() | ||
{ | ||
KeySizeValue = DefaultKeySize; | ||
BlockSizeValue = DefaultBlockSize; | ||
FeedbackSizeValue = DefaultFeedbackSize; | ||
LegalBlockSizesValue = DefaultLegalBlockSizes; | ||
LegalKeySizesValue = DefaultLegalKeySizes; | ||
} | ||
|
||
/// <summary> | ||
/// Ðàçìåð êëþ÷à 256 áèò. | ||
/// </summary> | ||
internal const int DefaultBlockSize = 64; | ||
/// <summary> | ||
/// Ðàçìåð áëîêà 64 áèòà. | ||
/// </summary> | ||
internal const int DefaultKeySize = 256; | ||
/// <summary> | ||
/// Ðàçìåð çàöåïëåíèÿ 64 áèòà. | ||
/// </summary> | ||
internal const int DefaultFeedbackSize = 64; | ||
/// <summary> | ||
/// Ðàçìåð ñèíõðîïîñûëêè 64 áèòà. | ||
/// </summary> | ||
internal const int DefaultIvSize = 64; | ||
|
||
public static readonly KeySizes[] DefaultLegalKeySizes = { new KeySizes(DefaultKeySize, DefaultKeySize, 0) }; | ||
public static readonly KeySizes[] DefaultLegalBlockSizes = { new KeySizes(DefaultBlockSize, DefaultBlockSize, 0) }; | ||
|
||
|
||
/// <summary> | ||
/// Ñîçäàíèå îáúåêòà, ðåàëèçóåùåãî àëãîðèòì øèôðîâàíèÿ ÃÎÑÒ-28147. | ||
/// </summary> | ||
/// | ||
/// <returns>Êðèïòîãðàôè÷åñêèé îáúåêò, ðåàëèçóþùèé àëãîðèòì ÃÎÑÒ | ||
/// 28147.</returns> | ||
/// | ||
/// <remarks><para>Ñîçäàíèå îáúåêòà àëãîðèòìà øèôðîâàíèÿ ÃÎÑÒ 28147. | ||
/// Îáúåêò ìîæåò èñïîëüçîâàòüñÿ | ||
/// äëÿ ñèììåòðè÷íîãî çàøèôðîâàíèÿ è ðàñøèôðîâàíèÿ.</para></remarks> | ||
/// | ||
/// <doc-sample path="Simple\Encrypt" name="EncryptDecryptRandomFile" | ||
/// region="EncryptDecryptRandomFile">Ïðèìåð çàøèôðîâàíèÿ è | ||
/// ðàñøèôðîâàíèÿ ôàéëà ïðè ïîìîùè | ||
/// ïîðîæäåííîãî êëàññà <see cref="Gost28147CryptoServiceProvider"/>. | ||
/// </doc-sample> | ||
public static new Gost28147 Create() | ||
{ | ||
// Ñîçäàíèå îáúåêòà èäåò ïî êîíôèãóðàöèè äëÿ àëãîðèòìà çàäàííîãî | ||
// ïîëíûì èìåíåì êëàññà Gost28147. | ||
return Gost28147.Create(typeof(Gost28147).FullName); | ||
} | ||
|
||
/// <summary> | ||
/// Ñîçäàíèå îáúåêòà, ðåàëèçóþùåãî àëãîðèòì øèôðîâàíèÿ ÃÎÑÒ-28147 | ||
/// ñ çàäàííûì èìåíåì ðåàëèçàöèè. | ||
/// </summary> | ||
/// | ||
/// <param name="algName">Èìÿ ðåàëèçàöèè àëãîðèòìà.</param> | ||
/// | ||
/// <returns>Êðèïòîãðàôè÷åñêèé îáúåêò, ðåàëèçóþùèé àëãîðèòì | ||
/// ÃÎÑÒ 28147.</returns> | ||
/// | ||
/// <doc-sample path="Simple\Encrypt" name="EncryptDecryptRandomFile" | ||
/// region="EncryptDecryptRandomFile">Ïðèìåð çàøèôðîâàíèÿ è | ||
/// ðàñøèôðîâàíèÿ ôàéëà ïðè ïîìîùè | ||
/// ïîðîæäåííîãî êëàññà <see cref="Gost28147CryptoServiceProvider"/>. | ||
/// </doc-sample> | ||
public static new Gost28147 Create(string algName) | ||
{ | ||
// Ñîçäàíèå îáúåêòà èäåò ïî êîíôèãóðàöèè äëÿ àëãîðèòìà çàäàííîãî | ||
// ïàðàìåòðîì. | ||
return (Gost28147)CryptoConfig.CreateFromName(algName); | ||
} | ||
|
||
/// <summary> | ||
/// Õýøèðóåò ñåêðåòíûé êëþ÷. | ||
/// </summary> | ||
/// | ||
/// <param name="hash">Êëàññ, ðåàëèçóþùèé ôóíêöèþ õýøèðîâàíèÿ.</param> | ||
/// | ||
/// <returns>Õýø-çíà÷åíèå ñåêðåòíîãî êëþ÷à</returns> | ||
public abstract byte[] ComputeHash(HashAlgorithm hash); | ||
|
||
/// <summary> | ||
/// Ýêñïîðòèðóåò (øèôðóåò) ñåêðåòíûé êëþ÷. | ||
/// </summary> | ||
/// <param name="keyExchangeAlgorithm">Îáùèé ñåêðåòíûé êëþ÷.</param> | ||
/// <param name="keyExchangeExportMethod">Àëãîðèòì ýêñïîðòà îáùåãî ñåêðåòíîãî êëþ÷à.</param> | ||
public abstract byte[] EncodePrivateKey(Gost28147 keyExchangeAlgorithm, GostKeyExchangeExportMethod keyExchangeExportMethod); | ||
|
||
/// <summary> | ||
/// Èìïîðòèðóåò (äåøèôðóåò) ñåêðåòíûé êëþ÷. | ||
/// </summary> | ||
/// <param name="encodedKeyExchangeData">Çàøèôðîâàííûé îáùèé ñåêðåòíûé êëþ÷.</param> | ||
/// <param name="keyExchangeExportMethod">Àëãîðèòì ýêñïîðòà îáùåãî ñåêðåòíîãî êëþ÷à.</param> | ||
public abstract SymmetricAlgorithm DecodePrivateKey(byte[] encodedKeyExchangeData, GostKeyExchangeExportMethod keyExchangeExportMethod); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...y.Cryptography.Algorithms/src/System/Security/Cryptography/GostKeyExchangeExportMethod.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Runtime.InteropServices; | ||
|
||
namespace System.Security.Cryptography | ||
{ | ||
/// <summary> | ||
/// Àëãîðèòì ýêñïîðòà îáùåãî ñåêðåòíîãî êëþ÷à. | ||
/// </summary> | ||
public enum GostKeyExchangeExportMethod | ||
{ | ||
/// <summary> | ||
/// Ïðîñòîé ýêñïîðò êëþ÷à ïî ÃÎÑÒ 28147-89. | ||
/// </summary> | ||
GostKeyExport, | ||
|
||
/// <summary> | ||
/// Çàùèù¸ííûé ýêñïîðò êëþ÷à ïî àëãîðèòìó ÊðèïòîÏðî. | ||
/// </summary> | ||
CryptoProKeyExport | ||
} | ||
} |