本文整理汇总了C#中EncryptionAlgorithm类的典型用法代码示例。如果您正苦于以下问题:C# EncryptionAlgorithm类的具体用法?C# EncryptionAlgorithm怎么用?C# EncryptionAlgorithm使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EncryptionAlgorithm类属于命名空间,在下文中一共展示了EncryptionAlgorithm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShowDialog
public bool ShowDialog(Window owner, EncryptionAlgorithm value)
{
Owner = owner;
AlgorithmBox.Focus();
Keyboard.Focus(AlgorithmBox);
AlgorithmBox.Items.Clear();
foreach (var enumvalue in Enum.GetValues(typeof (EncryptionAlgorithm)))
{
AlgorithmBox.Items.Add(enumvalue);
}
AlgorithmBox.SelectedItem = value;
if (ShowDialog() ?? false)
{
Algorithm = (EncryptionAlgorithm) AlgorithmBox.SelectedItem;
return true;
}
else
{
Algorithm = EncryptionAlgorithm.Plain;
return false;
}
}
示例2: Decrypt
public static string Decrypt(EncryptionAlgorithm algorithm, CiphertextFormat format, string data, Key key,
byte[] salt, byte[] iv, PaddingMode paddingMode)
{
var _d = new byte[0];
switch (format)
{
case CiphertextFormat.Base64:
{
_d = Convert.FromBase64String(data);
break;
}
case CiphertextFormat.Hex:
{
_d = HexToByteArray(data);
break;
}
case CiphertextFormat.Url:
{
var encoding = new UTF8Encoding();
_d = encoding.GetBytes(HttpUtility.UrlDecode(data));
break;
}
}
return Decrypt(algorithm, _d, key, salt, iv, paddingMode);
}
示例3: ValidateEncryptionAlgorithm
public static bool ValidateEncryptionAlgorithm(EncryptionAlgorithm value)
{
if ((value != EncryptionAlgorithm.None) && (value != EncryptionAlgorithm.Rc2))
{
return (value == EncryptionAlgorithm.Rc4);
}
return true;
}
示例4: ValidateEncryptionAlgorithm
public static bool ValidateEncryptionAlgorithm(EncryptionAlgorithm value)
{
//
// note that EncryptionAlgorithm has disjoined values
//
return (value == EncryptionAlgorithm.None) ||
(value == EncryptionAlgorithm.Rc2) ||
(value == EncryptionAlgorithm.Rc4);
}
示例5: CmsRecipient
/// <summary>
/// Initializes a new instance of the <see cref="MimeKit.Cryptography.CmsRecipient"/> class.
/// </summary>
/// <remarks>
/// The initial value of the <see cref="EncryptionAlgorithms"/> property will be set to
/// the Triple-DES encryption algorithm, which should be safe to assume for all modern
/// S/MIME v3.x client implementations.
/// </remarks>
/// <param name="certificate">The recipient's certificate.</param>
/// <param name="recipientIdentifierType">The recipient identifier type.</param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="certificate"/> is <c>null</c>.
/// </exception>
public CmsRecipient (X509Certificate certificate, SubjectIdentifierType recipientIdentifierType = SubjectIdentifierType.IssuerAndSerialNumber)
{
if (certificate == null)
throw new ArgumentNullException (nameof (certificate));
if (recipientIdentifierType == SubjectIdentifierType.IssuerAndSerialNumber)
RecipientIdentifierType = SubjectIdentifierType.IssuerAndSerialNumber;
else
RecipientIdentifierType = SubjectIdentifierType.SubjectKeyIdentifier;
EncryptionAlgorithms = new EncryptionAlgorithm[] { EncryptionAlgorithm.TripleDes };
Certificate = certificate;
}
示例6: Create
public static IEncryptionAlgorithm Create(EncryptionAlgorithm algoType)
{
IEncryptionAlgorithm encryptionInstance = null;
switch (algoType) {
case EncryptionAlgorithm.AES:
encryptionInstance = new Encryption.AES();
break;
case EncryptionAlgorithm.Rijndael:
encryptionInstance = new Encryption.Rijndael();
break;
default:
throw new Exception("Incorrect use of EncryptionAlgoritm factory");
}
return encryptionInstance;
}
示例7: CreateCipher
public virtual TlsCipher CreateCipher(TlsClientContext context,
EncryptionAlgorithm encryptionAlgorithm, DigestAlgorithm digestAlgorithm)
{
switch (encryptionAlgorithm)
{
case EncryptionAlgorithm.cls_3DES_EDE_CBC:
return CreateDesEdeCipher(context, 24, digestAlgorithm);
case EncryptionAlgorithm.AES_128_CBC:
return CreateAesCipher(context, 16, digestAlgorithm);
case EncryptionAlgorithm.AES_256_CBC:
return CreateAesCipher(context, 32, digestAlgorithm);
default:
throw new TlsFatalAlert(AlertDescription.internal_error);
}
}
示例8: PasspadDocument
private PasspadDocument(EncryptionAlgorithm algo, SecureString pw, string content, string hint, string file)
{
fileAlgorithm = algo;
Algorithm = algo;
filePassword = pw;
Password = pw;
fileContent = content;
Content = content;
fileHint = hint;
Hint = hint;
File = file;
}
示例9: SaveFile
public static void SaveFile(string file, string text, string hint, SecureString password, EncryptionAlgorithm algorithm)
{
var data = AbstractEncryptionAlgorithm.GetAlgorithm(algorithm).Encode(text, password);
var data64 = Convert.ToBase64String(data);
StringBuilder result = new StringBuilder();
result.AppendLine(string.Format("<hint>{0}</hint>", SecurityElement.Escape(hint)));
result.AppendLine(string.Format("<encrypted algorithm=\"{0}\">", algorithm));
for (int i = 0; i < Math.Ceiling(data64.Length / 64.0); i++)
{
result.AppendLine(" " + data64.Substring(i*64, Math.Min(64, data64.Length - i * 64)));
}
result.AppendLine("</encrypted>");
File.WriteAllText(file, result.ToString(), Encoding.UTF8);
}
示例10: ReadFile
public static string ReadFile(XDocument xdoc, SecureString password, out EncryptionAlgorithm algorithm)
{
if (!Enum.TryParse(xdoc.Root?.Element("encrypted")?.Attribute("algorithm").Value ?? string.Empty, true, out algorithm))
{
algorithm = EncryptionAlgorithm.Plain;
return null;
}
var data = (xdoc.Root?.Element("encrypted")?.Value ?? string.Empty)
.Replace("\t", "")
.Replace(" ", "")
.Replace("\r", "")
.Replace("\n", "")
.Trim();
var bdata = Convert.FromBase64String(data);
return AbstractEncryptionAlgorithm.GetAlgorithm(algorithm).Decode(bdata, password);
}
示例11: CreateAuthenticatedEncryptor_RoundTripsData_CngGcmImplementation
public void CreateAuthenticatedEncryptor_RoundTripsData_CngGcmImplementation(EncryptionAlgorithm encryptionAlgorithm)
{
// Parse test input
int keyLengthInBits = Int32.Parse(Regex.Match(encryptionAlgorithm.ToString(), @"^AES_(?<keyLength>\d{3})_GCM$").Groups["keyLength"].Value, CultureInfo.InvariantCulture);
// Arrange
var masterKey = Secret.Random(512 / 8);
var control = new GcmAuthenticatedEncryptor(
keyDerivationKey: masterKey,
symmetricAlgorithmHandle: CachedAlgorithmHandles.AES_GCM,
symmetricAlgorithmKeySizeInBytes: (uint)(keyLengthInBits / 8));
var test = CreateDescriptor(encryptionAlgorithm, ValidationAlgorithm.HMACSHA256 /* unused */, masterKey).CreateEncryptorInstance();
// Act & assert - data round trips properly from control to test
byte[] plaintext = new byte[] { 1, 2, 3, 4, 5 };
byte[] aad = new byte[] { 2, 4, 6, 8, 0 };
byte[] ciphertext = control.Encrypt(new ArraySegment<byte>(plaintext), new ArraySegment<byte>(aad));
byte[] roundTripPlaintext = test.Decrypt(new ArraySegment<byte>(ciphertext), new ArraySegment<byte>(aad));
Assert.Equal(plaintext, roundTripPlaintext);
}
示例12: CreateAuthenticatedEncryptor_RoundTripsData_ManagedImplementation
public void CreateAuthenticatedEncryptor_RoundTripsData_ManagedImplementation(EncryptionAlgorithm encryptionAlgorithm, ValidationAlgorithm validationAlgorithm)
{
// Parse test input
int keyLengthInBits = Int32.Parse(Regex.Match(encryptionAlgorithm.ToString(), @"^AES_(?<keyLength>\d{3})_CBC$").Groups["keyLength"].Value, CultureInfo.InvariantCulture);
// Arrange
var masterKey = Secret.Random(512 / 8);
var control = new ManagedAuthenticatedEncryptor(
keyDerivationKey: masterKey,
symmetricAlgorithmFactory: () => new AesCryptoServiceProvider(),
symmetricAlgorithmKeySizeInBytes: keyLengthInBits / 8,
validationAlgorithmFactory: () => KeyedHashAlgorithm.Create(validationAlgorithm.ToString()));
var test = CreateDescriptor(encryptionAlgorithm, validationAlgorithm, masterKey).CreateEncryptorInstance();
// Act & assert - data round trips properly from control to test
byte[] plaintext = new byte[] { 1, 2, 3, 4, 5 };
byte[] aad = new byte[] { 2, 4, 6, 8, 0 };
byte[] ciphertext = control.Encrypt(new ArraySegment<byte>(plaintext), new ArraySegment<byte>(aad));
byte[] roundTripPlaintext = test.Decrypt(new ArraySegment<byte>(ciphertext), new ArraySegment<byte>(aad));
Assert.Equal(plaintext, roundTripPlaintext);
}
示例13: GetAlgorithm
public static AbstractEncryptionAlgorithm GetAlgorithm(EncryptionAlgorithm algo)
{
switch (algo)
{
case EncryptionAlgorithm.Plain:
return new AlgorithmPlain();
case EncryptionAlgorithm.Blowfish:
return new AlgorithmBlowfish();
case EncryptionAlgorithm.Twofish:
return new AlgorithmTwofish();
case EncryptionAlgorithm.AES:
return new AlgorithmAES();
case EncryptionAlgorithm.TripleDES:
return new AlgorithmTripleDES();
case EncryptionAlgorithm.CAST:
return new AlgorithmCAST();
case EncryptionAlgorithm.XOR:
return new AlgorithmXOR();
case EncryptionAlgorithm.DES:
return new AlgorithmDES();
default:
throw new NotImplementedException();
}
}
示例14: Decrypt
/// <summary>
/// �ṩ����ʵ�ֽ��ܵķ���
/// </summary>
/// <param name="algorithm"></param>
/// <param name="bytesData">��Ҫ���ܵ���Ϣ</param>
/// <returns></returns>
public byte[] Decrypt(EncryptionAlgorithm algorithm, byte[] bytesData)
{
byte[] result = new byte[0];
using (MemoryStream stream = new MemoryStream())
{
ICryptoTransform cryptoServiceProvider = GetDecryptoServiceProvider(algorithm);
using (CryptoStream stream2 = new CryptoStream(stream, cryptoServiceProvider, CryptoStreamMode.Write))
{
try
{
stream2.Write(bytesData, 0, bytesData.Length);
stream2.FlushFinalBlock();
stream2.Close();
result = stream.ToArray();
}
catch (Exception exception)
{
throw new Exception("Error while writing decrypted data to the stream: \n" + exception.Message);
}
}
stream.Close();
}
return result;
}
示例15: GetLengthOfCryptoHeaderBytes
internal static int GetLengthOfCryptoHeaderBytes(EncryptionAlgorithm a)
{
//if ((_BitField & 0x01) != 0x01) return 0;
if (a == EncryptionAlgorithm.None) return 0;
#if AESCRYPTO
if (a == EncryptionAlgorithm.WinZipAes128 ||
a == EncryptionAlgorithm.WinZipAes256)
{
int KeyStrengthInBits = GetKeyStrengthInBits(a);
int sizeOfSaltAndPv = ((KeyStrengthInBits / 8 / 2) + 2);
return sizeOfSaltAndPv;
}
#endif
if (a == EncryptionAlgorithm.PkzipWeak)
return 12;
throw new ZipException("internal error");
}