• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# EncryptionAlgorithm类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中EncryptionAlgorithm的典型用法代码示例。如果您正苦于以下问题:C# EncryptionAlgorithm类的具体用法?C# EncryptionAlgorithm怎么用?C# EncryptionAlgorithm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



EncryptionAlgorithm类属于命名空间,在下文中一共展示了EncryptionAlgorithm类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: GetKeyStrengthInBits

 private static int GetKeyStrengthInBits(EncryptionAlgorithm a)
 {
     if (a == EncryptionAlgorithm.WinZipAes256) return 256;
     else if (a == EncryptionAlgorithm.WinZipAes128) return 128;
     return -1;
 }
开发者ID:Ginichen,项目名称:Silverlight-Player-for-PlayReady-with-Token-Auth,代码行数:6,代码来源:ZipEntry.cs


示例17: Decryptor

 public Decryptor(EncryptionAlgorithm algId)
 {
     transformer = new DecryptTransformer(algId);
 }
开发者ID:nothingmn,项目名称:robchartier-classlibrary,代码行数:4,代码来源:Decryptor.cs


示例18: RadioButton4_CheckedChanged

 void RadioButton4_CheckedChanged(object sender, EventArgs e)
 {
     if (RadioButton1.Checked) {
         MahEncType = EncryptionAlgorithm.None;
     } else if (RadioButton2.Checked) {
         MahEncType = EncryptionAlgorithm.PkzipWeak;
     } else if (RadioButton3.Checked) {
         MahEncType = EncryptionAlgorithm.WinZipAes128;
     } else if (RadioButton4.Checked) {
         MahEncType = EncryptionAlgorithm.WinZipAes256;
     } else {
         MessageBox.Show("Error: Invalid Encryption Type!");
     }
 }
开发者ID:mlnlover11,项目名称:iTunes-Helper,代码行数:14,代码来源:LibraryBackupForm.cs


示例19: _Zip64_Over65534Entries

        void _Zip64_Over65534Entries(Zip64Option z64option,
                                            EncryptionAlgorithm encryption,
                                            Ionic.Zlib.CompressionLevel compression)
        {
            // Emitting a zip file with > 65534 entries requires the use of ZIP64 in
            // the central directory.
            int numTotalEntries = _rnd.Next(4616)+65534;
            //int numTotalEntries = _rnd.Next(461)+6534;
            //int numTotalEntries = _rnd.Next(46)+653;
            string enc = encryption.ToString();
            if (enc.StartsWith("WinZip")) enc = enc.Substring(6);
            else if (enc.StartsWith("Pkzip")) enc = enc.Substring(0,5);
            string zipFileToCreate = String.Format("Zip64.ZF_Over65534.{0}.{1}.{2}.zip",
                                                   z64option.ToString(),
                                                   enc,
                                                   compression.ToString());

            _testTitle = String.Format("ZipFile #{0} 64({1}) E({2}), C({3})",
                                       numTotalEntries,
                                       z64option.ToString(),
                                       enc,
                                       compression.ToString());
            _txrx = TestUtilities.StartProgressMonitor(zipFileToCreate,
                                                       _testTitle,
                                                       "starting up...");

            _txrx.Send("pb 0 max 4"); // 3 stages: AddEntry, Save, Verify
            _txrx.Send("pb 0 value 0");

            string password = Path.GetRandomFileName();

            string statusString = String.Format("status Encrypt:{0} Compress:{1}...",
                                                enc,
                                                compression.ToString());

            int numSaved = 0;
            var saveProgress = new EventHandler<SaveProgressEventArgs>( (sender, e) => {
                    switch (e.EventType)
                    {
                        case ZipProgressEventType.Saving_Started:
                        _txrx.Send("status saving...");
                        _txrx.Send("pb 1 max " + numTotalEntries);
                        numSaved= 0;
                        break;

                        case ZipProgressEventType.Saving_AfterWriteEntry:
                        numSaved++;
                        if ((numSaved % 128) == 0)
                        {
                            _txrx.Send("pb 1 value " + numSaved);
                            _txrx.Send(String.Format("status Saving entry {0}/{1} ({2:N0}%)",
                                                     numSaved, numTotalEntries,
                                                     numSaved / (0.01 * numTotalEntries)
                                                     ));
                        }
                        break;

                        case ZipProgressEventType.Saving_Completed:
                        _txrx.Send("status Save completed");
                        _txrx.Send("pb 1 max 1");
                        _txrx.Send("pb 1 value 1");
                        break;
                    }
                });

            string contentFormatString =
                "This is the content for entry #{0}.\r\n\r\n" +
                "AAAAAAA BBBBBB AAAAA BBBBB AAAAA BBBBB AAAAA\r\n"+
                "AAAAAAA BBBBBB AAAAA BBBBB AAAAA BBBBB AAAAA\r\n";
            _txrx.Send(statusString);
            int dirCount= 0;
            using (var zip = new ZipFile())
            {
                _txrx.Send(String.Format("pb 1 max {0}", numTotalEntries));
                _txrx.Send("pb 1 value 0");

                zip.Password = password;
                zip.Encryption = encryption;
                zip.CompressionLevel = compression;
                zip.SaveProgress += saveProgress;
                zip.UseZip64WhenSaving = z64option;
                // save space when saving the file:
                zip.EmitTimesInWindowsFormatWhenSaving = false;
                zip.EmitTimesInUnixFormatWhenSaving = false;

                // add files:
                for (int m=0; m<numTotalEntries; m++)
                {
                    if (_rnd.Next(7)==0)
                    {
                        string entryName = String.Format("{0:D5}", m);
                        zip.AddDirectoryByName(entryName);
                        dirCount++;
                    }
                    else
                    {
                        string entryName = String.Format("{0:D5}.txt", m);
                        if (_rnd.Next(12)==0)
                        {
                            string contentBuffer = String.Format(contentFormatString, m);
//.........这里部分代码省略.........
开发者ID:mattleibow,项目名称:Zip.Portable,代码行数:101,代码来源:Zip64Tests.cs


示例20: SetEncryption

 /// <summary>
 /// Set the password and algorithm used by the Berkeley DB library to
 /// perform encryption and decryption. 
 /// </summary>
 /// <param name="password">
 /// The password used to perform encryption and decryption.
 /// </param>
 /// <param name="alg">
 /// The algorithm used to perform encryption and decryption.
 /// </param>
 public void SetEncryption(String password, EncryptionAlgorithm alg)
 {
     encryptionIsSet = true;
     encryptPwd = password;
     encryptAlg = alg;
 }
开发者ID:sukantoguha,项目名称:INET-Vagrant-Demos,代码行数:16,代码来源:DatabaseConfig.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# EncryptionPolicy类代码示例发布时间:2022-05-24
下一篇:
C# Encryption类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap