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


C# RijndaelManaged.GenerateKey方法代码示例

本文整理汇总了C#中System.Security.Cryptography.RijndaelManaged.GenerateKey方法的典型用法代码示例。如果您正苦于以下问题:C# RijndaelManaged.GenerateKey方法的具体用法?C# RijndaelManaged.GenerateKey怎么用?C# RijndaelManaged.GenerateKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.Cryptography.RijndaelManaged的用法示例。


在下文中一共展示了RijndaelManaged.GenerateKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateEncryptionKey

 /// -------------- Two Utility Methods (not used but may be useful) -----------
 /// Generates an encryption key.
 public static byte[] GenerateEncryptionKey()
 {
     //Generate a Key.
     RijndaelManaged rm = new RijndaelManaged();
     rm.GenerateKey();
     return rm.Key;
 }
开发者ID:nicoriff,项目名称:NinoJS,代码行数:9,代码来源:AES.cs

示例2: GenerateKey

        public static byte[] GenerateKey()
        {
            RijndaelManaged provider = new RijndaelManaged();
              provider.GenerateKey();

              return provider.Key;
        }
开发者ID:okyereadugyamfi,项目名称:softlogik,代码行数:7,代码来源:EncryptionUtils.cs

示例3: RandomKey

 public static byte[] RandomKey(int length)
 {
     var alg = new RijndaelManaged();
     alg.KeySize = length * 8;
     alg.GenerateKey();
     return alg.Key;
 }
开发者ID:exaphaser,项目名称:megadesktop,代码行数:7,代码来源:Crypto.cs

示例4: CreateBlob

        /// <summary>
        /// Create an AES key that is encrypted using a RSA certificate, this is the parsed version for increased efficiancy
        /// 
        /// To create the parsed cert <see cref="Kalix.ApiCrypto.RSA.RSACertificateParser.ParsePublicCertificate"/>
        /// </summary>
        /// <param name="keySize">Required AES key size</param>
        /// <param name="rsaCert">RSA parsed public certificate used to sign</param>
        /// <returns>data that can be stored</returns>
        public static byte[] CreateBlob(AESKeySize keySize, RSAServiceProvider rsaCert)
        {
            int intKeySize;
            switch (keySize)
            {
                case AESKeySize.AES128:
                    intKeySize = 128;
                    break;
                case AESKeySize.AES192:
                    intKeySize = 192;
                    break;
                case AESKeySize.AES256:
                    intKeySize = 256;
                    break;
                default:
                    throw new ArgumentOutOfRangeException("keySize", "Unknown key size");
            }

            var aesProvider = new RijndaelManaged();
            aesProvider.KeySize = intKeySize;
            aesProvider.GenerateKey();

            // Encrypt using the RSA cert and return
            return rsaCert.EncryptValue(aesProvider.Key);
        }
开发者ID:KalixHealth,项目名称:Kalix.ApiCrypto,代码行数:33,代码来源:AESBlob.cs

示例5: EncodeEx

        public static string EncodeEx(string data, out string hexKey)
        {
            RijndaelManaged aes = new RijndaelManaged();
            aes.KeySize = 256;
            aes.BlockSize = 128;
            aes.Mode = CipherMode.CBC;
            aes.Padding = PaddingMode.PKCS7;
            aes.GenerateKey();
            aes.IV = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

            var encrypt = aes.CreateEncryptor(aes.Key, aes.IV);
            byte[] xBuff = null;
            using (var ms = new MemoryStream())
            {
                using (var cs = new CryptoStream(ms, encrypt, CryptoStreamMode.Write))
                {
                    byte[] xXml = Encoding.UTF8.GetBytes(data);
                    cs.Write(xXml, 0, xXml.Length);
                }

                xBuff = ms.ToArray();
            }

            hexKey = BitConverter.ToString(aes.Key).Replace("-", "");

            string result = Convert.ToBase64String(xBuff);
            return result;
        }
开发者ID:NeuroWhAI,项目名称:ClickWar,代码行数:28,代码来源:EncoderDecoder.cs

示例6: Main

 static void Main(string[] args)
 {
     RijndaelManaged rm = new RijndaelManaged();
     rm.GenerateKey();
     rm.GenerateIV();
     string key = Convert.ToBase64String(rm.Key);
     string iv = Convert.ToBase64String(rm.IV);
 }
开发者ID:Karmadilla,项目名称:KeyIvGenerator,代码行数:8,代码来源:Program.cs

示例7: Decrypt

        public static string Decrypt(byte[] encryptedString) {
            using (var myRijndael = new RijndaelManaged()) {
                myRijndael.GenerateKey();
                myRijndael.GenerateIV();

                return DecryptStringFromBytes(encryptedString, myRijndael.Key, myRijndael.IV);
            }
        }
开发者ID:jcapellman,项目名称:jcBP,代码行数:8,代码来源:Encryption.cs

示例8: Encrypt

        public static byte[] Encrypt(string unencryptedString) {
            using (var myRijndael = new RijndaelManaged()) {
                myRijndael.GenerateKey();
                myRijndael.GenerateIV();

                return EncryptStringToBytes(unencryptedString, myRijndael.Key, myRijndael.IV);
            }
        }
开发者ID:jcapellman,项目名称:jcBP,代码行数:8,代码来源:Encryption.cs

示例9: GeneraSegreto

 /// <summary>
 /// Genera un segreto compatibile per la trasmissione in URL che deve essere protetto e condiviso dalle parti che vogliono scambiare i messaggi in maniera cifrata.
 /// </summary>
 /// <returns>Segreto</returns>
 public string GeneraSegreto()
 {
     using (var myRijndael = new RijndaelManaged())
     {
         myRijndael.GenerateKey();
         return HttpServerUtility.UrlTokenEncode(myRijndael.Key);
     }
 }
开发者ID:tu226,项目名称:Cryptography,代码行数:12,代码来源:UrlCompatibleCipher.cs

示例10: CreateSymmetricKey

        public void CreateSymmetricKey()
        {
            symmetricAlgo = (RijndaelManaged)RijndaelManaged.Create();
            symmetricAlgo.GenerateKey();
            encryptedKey = ProtectedData.Protect(symmetricAlgo.Key, null, DataProtectionScope.CurrentUser);

            stream = new MemoryStream();
        }
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:8,代码来源:KeyWriterFixture.cs

示例11: Base64EncodedRijndaelKeyVectorPair

 public Base64EncodedRijndaelKeyVectorPair()
 {
     RijndaelManaged rm = new RijndaelManaged();
     rm.GenerateKey();
     rm.GenerateIV();
     this.Key = Convert.ToBase64String(rm.Key);
     this.IV = Convert.ToBase64String(rm.IV);
 }
开发者ID:BryanApellanes,项目名称:Naizari,代码行数:8,代码来源:Base64EncodedRijndaelKeyVectorPair.cs

示例12: GenerateNewKey

 string GenerateNewKey()
 {
     using (var rijndael = new RijndaelManaged())
     {
         rijndael.GenerateKey();
         
         return Convert.ToBase64String(rijndael.Key);
     }
 }
开发者ID:mhertis,项目名称:Rebus,代码行数:9,代码来源:Encryptor.cs

示例13: Process

		public override void Process(Command command)
		{
			var options = this.LoadOptions<CommandOptions>((TextCommand)command);

			if (options.Modulus != null && options.Exponent != null && options.Algorithm != null)
			{
				var symmetric = new RijndaelManaged();
				symmetric.GenerateKey();

				var modulus = TextConversion.FromBase64String(options.Modulus);
				var exponent = TextConversion.FromBase64String(options.Exponent);

				var rsaparameters = new RSAParameters();
				rsaparameters.Modulus = modulus;
				rsaparameters.Exponent = exponent;
				
				var rsa = new RSACryptoServiceProvider();
				rsa.ImportParameters(rsaparameters);
				
				var myrsa = new RSACryptoServiceProvider();

				rsaparameters = myrsa.ExportParameters(false);

				Connection.WriteOk
				(
					"Modulus",
					TextConversion.ToBase64String(rsaparameters.Modulus),
					"Exponent",
					TextConversion.ToBase64String(rsaparameters.Exponent),
					"IV",
					TextConversion.ToBase64String(new RSAPKCS1KeyExchangeFormatter(rsa).CreateKeyExchange(symmetric.IV)),
					"KeyExchange",
					TextConversion.ToBase64String(new RSAPKCS1KeyExchangeFormatter(rsa).CreateKeyExchange(symmetric.Key))
				);

				Connection.Flush();

				if (options.WaitForReady)
				{
					Connection.ReadReady();
				}
			}
			else if (options.Compress)
			{
				Connection.WriteOk();
				Connection.Flush();

				this.Connection.ReadStream = new InteractiveInflaterInputStream(this.Connection.RawReadStream, new Inflater(true));
				this.Connection.WriteStream = new InteractiveDeflaterOutputStream(this.Connection.RawWriteStream, new Deflater(Deflater.DEFAULT_COMPRESSION, true), 512);

				if (options.WaitForReady)
				{
					Connection.ReadReady();
				}
			}
		}
开发者ID:Euphrates-Media,项目名称:Platform.VirtualFileSystem,代码行数:56,代码来源:AdhocEncryptionCommandProcessor.cs

示例14: CreateSecretKey

        /// store a key into a text file
        static public bool CreateSecretKey(string ASecretKeyFile)
        {
            Rijndael alg = new RijndaelManaged();

            alg.GenerateKey();
            StreamWriter sw = new StreamWriter(ASecretKeyFile);
            sw.Write(Convert.ToBase64String(alg.Key));
            sw.Close();
            return true;
        }
开发者ID:Davincier,项目名称:openpetra,代码行数:11,代码来源:Encryption.cs

示例15: CreateAes

 public static SymmetricAlgorithm CreateAes()
 {
     var alg = new RijndaelManaged();
     alg.GenerateKey();
     alg.BlockSize = 128;
     alg.KeySize = 128;
     alg.Mode = CipherMode.ECB;
     alg.Padding = PaddingMode.None;
     return alg;
 }
开发者ID:exaphaser,项目名称:megadesktop,代码行数:10,代码来源:Crypto.cs


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