本文整理汇总了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;
}
示例2: GenerateKey
public static byte[] GenerateKey()
{
RijndaelManaged provider = new RijndaelManaged();
provider.GenerateKey();
return provider.Key;
}
示例3: RandomKey
public static byte[] RandomKey(int length)
{
var alg = new RijndaelManaged();
alg.KeySize = length * 8;
alg.GenerateKey();
return alg.Key;
}
示例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);
}
示例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;
}
示例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);
}
示例7: Decrypt
public static string Decrypt(byte[] encryptedString) {
using (var myRijndael = new RijndaelManaged()) {
myRijndael.GenerateKey();
myRijndael.GenerateIV();
return DecryptStringFromBytes(encryptedString, myRijndael.Key, myRijndael.IV);
}
}
示例8: Encrypt
public static byte[] Encrypt(string unencryptedString) {
using (var myRijndael = new RijndaelManaged()) {
myRijndael.GenerateKey();
myRijndael.GenerateIV();
return EncryptStringToBytes(unencryptedString, myRijndael.Key, myRijndael.IV);
}
}
示例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);
}
}
示例10: CreateSymmetricKey
public void CreateSymmetricKey()
{
symmetricAlgo = (RijndaelManaged)RijndaelManaged.Create();
symmetricAlgo.GenerateKey();
encryptedKey = ProtectedData.Protect(symmetricAlgo.Key, null, DataProtectionScope.CurrentUser);
stream = new MemoryStream();
}
示例11: Base64EncodedRijndaelKeyVectorPair
public Base64EncodedRijndaelKeyVectorPair()
{
RijndaelManaged rm = new RijndaelManaged();
rm.GenerateKey();
rm.GenerateIV();
this.Key = Convert.ToBase64String(rm.Key);
this.IV = Convert.ToBase64String(rm.IV);
}
示例12: GenerateNewKey
string GenerateNewKey()
{
using (var rijndael = new RijndaelManaged())
{
rijndael.GenerateKey();
return Convert.ToBase64String(rijndael.Key);
}
}
示例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;
}
示例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;
}