当前位置: 首页>>代码示例>>C#>>正文


C# EncryptionAlgorithm类代码示例

本文整理汇总了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;
            }
        }
开发者ID:Mikescher,项目名称:Passpad,代码行数:26,代码来源:ChangeAlgorithmDialog.xaml.cs

示例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);
 }
开发者ID:blinds52,项目名称:ActiveDirectoryServices,代码行数:25,代码来源:Crypto.cs

示例3: ValidateEncryptionAlgorithm

 public static bool ValidateEncryptionAlgorithm(EncryptionAlgorithm value)
 {
     if ((value != EncryptionAlgorithm.None) && (value != EncryptionAlgorithm.Rc2))
     {
         return (value == EncryptionAlgorithm.Rc4);
     }
     return true;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:8,代码来源:ValidationUtility.cs

示例4: ValidateEncryptionAlgorithm

 public static bool ValidateEncryptionAlgorithm(EncryptionAlgorithm value)
 {
     //
     // note that EncryptionAlgorithm has disjoined values
     //
     return (value == EncryptionAlgorithm.None) ||
            (value == EncryptionAlgorithm.Rc2) ||
            (value == EncryptionAlgorithm.Rc4);
 }
开发者ID:JianwenSun,项目名称:cc,代码行数:9,代码来源:ValidationUtility.cs

示例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;
		}
开发者ID:cybercircuits,项目名称:MimeKit,代码行数:26,代码来源:CmsRecipient.cs

示例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;
 }
开发者ID:fitzbigman,项目名称:CMCoreNET,代码行数:15,代码来源:SecurityFactories.cs

示例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);
			}
		}
开发者ID:Xanagandr,项目名称:DisaOpenSource,代码行数:15,代码来源:DefaultTlsCipherFactory.cs

示例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;
        }
开发者ID:Mikescher,项目名称:Passpad,代码行数:16,代码来源:PasspadDocument.cs

示例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);
        }
开发者ID:Mikescher,项目名称:Passpad,代码行数:17,代码来源:EncryptionFileIO.cs

示例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);
        }
开发者ID:Mikescher,项目名称:Passpad,代码行数:19,代码来源:EncryptionFileIO.cs

示例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);
        }
开发者ID:supermason,项目名称:DataProtection,代码行数:20,代码来源:AuthenticatedEncryptorDescriptorTests.cs

示例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);
        }
开发者ID:supermason,项目名称:DataProtection,代码行数:21,代码来源:AuthenticatedEncryptorDescriptorTests.cs

示例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();
     }
 }
开发者ID:Mikescher,项目名称:Passpad,代码行数:24,代码来源:AbstractEncryptionAlgorithm.cs

示例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;
 }
开发者ID:WuziyiaoKingIris20140501,项目名称:KFC,代码行数:30,代码来源:EncryptTransform.cs

示例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");
        }
开发者ID:Ginichen,项目名称:Silverlight-Player-for-PlayReady-with-Token-Auth,代码行数:18,代码来源:ZipEntry.cs


注:本文中的EncryptionAlgorithm类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。