本文整理汇总了C#中EncryptionType类的典型用法代码示例。如果您正苦于以下问题:C# EncryptionType类的具体用法?C# EncryptionType怎么用?C# EncryptionType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EncryptionType类属于命名空间,在下文中一共展示了EncryptionType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: KrbFxCf2
public static byte[] KrbFxCf2(EncryptionType type, byte[] protocolKey1, byte[] protocolKey2, string pepper1, string pepper2)
{
byte[] octetString1 = null;
byte[] octetString2 = null;
switch (type)
{
case EncryptionType.AES256_CTS_HMAC_SHA1_96:
case EncryptionType.AES128_CTS_HMAC_SHA1_96:
{
octetString1 = AesPrfPlus(protocolKey1, Encoding.UTF8.GetBytes(pepper1));
octetString2 = AesPrfPlus(protocolKey2, Encoding.UTF8.GetBytes(pepper2));
break;
}
case EncryptionType.RC4_HMAC:
{
octetString1 = Rc4PrfPlus(protocolKey1, Encoding.UTF8.GetBytes(pepper1));
octetString2 = Rc4PrfPlus(protocolKey2, Encoding.UTF8.GetBytes(pepper2));
break;
}
default:
throw new NotSupportedException("Encryption type not support");
}
return RandomToKey(type, ExclusiveOr(octetString1, octetString2));
}
示例2: MakeKey
/// <summary>
/// Generate key according to password, salt and encryption type
/// </summary>
/// <param name="type">encryption type</param>
/// <param name="password">password</param>
/// <param name="salt">salt</param>
/// <returns>the generated key in bytes</returns>
public static byte[] MakeKey(EncryptionType type, string password, string salt)
{
switch (type)
{
case EncryptionType.AES128_CTS_HMAC_SHA1_96:
{
return AesKey.MakeStringToKey(password, salt,
AesKey.DEFAULT_ITERATION_COUNT, AesKeyType.Aes128BitsKey);
}
case EncryptionType.AES256_CTS_HMAC_SHA1_96:
{
return AesKey.MakeStringToKey(password, salt,
AesKey.DEFAULT_ITERATION_COUNT, AesKeyType.Aes256BitsKey);
}
case EncryptionType.DES_CBC_CRC:
case EncryptionType.DES_CBC_MD5:
{
return DesKey.MakeStringToKey(password, salt);
}
case EncryptionType.RC4_HMAC:
case EncryptionType.RC4_HMAC_EXP:
{
return Rc4Key.MakeStringToKey(password);
}
default:
throw new ArgumentException("Unsupported encryption type.");
}
}
示例3: Encode
public static String Encode(EncryptionType type, String algorithm, String plainText, String salt)
{
Byte[] arrText = Encoding.Unicode.GetBytes(plainText);
Byte[] arrSalt = Convert.FromBase64String(salt);
Byte[] arrAll = new Byte[arrText.Length + arrSalt.Length];
Byte[] arrResult = null;
Buffer.BlockCopy(arrText, 0, arrAll, 0, arrText.Length);
Buffer.BlockCopy(arrSalt, 0, arrAll, arrText.Length, arrSalt.Length);
//Buffer.BlockCopy(arrSalt, 0, arrAll, 0, arrSalt.Length);
//Buffer.BlockCopy(arrText, 0, arrAll, arrSalt.Length, arrAll.Length);
switch (type)
{
case EncryptionType.Clear:
return plainText;
case EncryptionType.Hashed:
using (HashAlgorithm hashAlgorithm = HashAlgorithm.Create(algorithm))
{
arrResult = hashAlgorithm.ComputeHash(arrAll);
}
return Convert.ToBase64String(arrResult);
case EncryptionType.Encrypted:
Byte[] key, iv;
GetEncryptionKeyAndIvFromSalt(salt, out key, out iv);
arrResult = EncryptStringToBytes(algorithm, Convert.ToBase64String(arrAll), key, iv);
return Convert.ToBase64String(arrResult);
default:
throw new InvalidOperationException("Unknown encryption type");
}
}
示例4: DataEncrypter
public DataEncrypter(EncryptionType Algo, String Key, String Vector)
{
_encryptionAlgorithm = Algo;
_key = Key;
_vector = Vector;
_data = "";
}
示例5: ClientRequestWrapper
/// <summary>
/// Initializes a new instance of the <see cref="ClientRequestWrapper"/> class.
/// </summary>
/// <param name="encryptionPublicKey">The encryption public key.</param>
/// <param name="encryption">The encryption.</param>
/// <param name="timeStamp">The time stamp.</param>
/// <param name="request">The request.</param>
public ClientRequestWrapper(byte[] encryptionPublicKey,
EncryptionType encryption,
DateTime timeStamp,
byte [] request)
: this(encryptionPublicKey, encryption, timeStamp, 0, request)
{
}
示例6: KerberosFunctionalClient
/// <summary>
/// Construct a Kerberos test client
/// </summary>
/// <param name="domain">The realm part of the client's principal identifier.
/// This argument cannot be null.</param>
/// <param name="cName">The account to logon the remote machine. Either user account or computer account
/// This argument cannot be null.</param>
/// <param name="password">The password of the user. This argument cannot be null.</param>
/// <param name="accountType">The type of the logon account. User or Computer</param>
public KerberosFunctionalClient(string domain, string cName, string password, KerberosAccountType accountType, string kdcAddress, int kdcPort, TransportType transportType, KerberosConstValue.OidPkt oidPkt, ITestSite baseTestSite,string salt = null)
: base(domain, cName, password, accountType, kdcAddress, kdcPort, transportType, oidPkt, salt)
{
testSite = baseTestSite;
if (accountType == KerberosAccountType.Device)
{
testSite.Log.Add(LogEntryKind.Debug, "Construct Kerberos client using computer account: {0}@{1}.",
cName, domain);
}
else
{
testSite.Log.Add(LogEntryKind.Debug, "Construct Kerberos client using user account: {0}@{1}.",
cName, domain);
}
EncryptionType[] encryptionTypes = new EncryptionType[]
{
EncryptionType.AES256_CTS_HMAC_SHA1_96,
EncryptionType.AES128_CTS_HMAC_SHA1_96,
EncryptionType.RC4_HMAC,
EncryptionType.RC4_HMAC_EXP,
EncryptionType.DES_CBC_CRC,
EncryptionType.DES_CBC_MD5
};
KerbInt32[] etypes = new KerbInt32[encryptionTypes.Length];
for (int i = 0; i < encryptionTypes.Length; i++)
{
etypes[i] = new KerbInt32((int)encryptionTypes[i]);
}
Asn1SequenceOf<KerbInt32> etype = new Asn1SequenceOf<KerbInt32>(etypes);
Context.SupportedEType = etype;
Context.Pvno = KerberosConstValue.KERBEROSV5;
}
示例7: Encrypt
public static string Encrypt(string text, EncryptionType CryptType)
{
string retVal = text;
//if (CryptType & EncryptionType.SIMPLE) {
// retVal = SimpleEncrypt(retVal);
//}
//if (CryptType & EncryptionType.HEX) {
// retVal = HexEncode(retVal);
//}
//if (CryptType & EncryptionType.REVERSE) {
// retVal = Strings.StrReverse(retVal);
//}
//if (CryptType & EncryptionType.BASE64) {
// retVal = Base64Encode(retVal);
//}
//if (CryptType & EncryptionType.ASCII) {
// retVal = ASCIIEncode(retVal);
//}
return retVal;
}
示例8: GenerateKeypair
public KeyPair GenerateKeypair(EncryptionType encryption)
{
int modulus;
switch (encryption)
{
case EncryptionType.RSA_512:
modulus = 512;
break;
case EncryptionType.RSA_1024:
modulus = 1024;
break;
case EncryptionType.RSA_1536:
modulus = 1536;
break;
case EncryptionType.RSA_2048:
modulus = 2048;
break;
case EncryptionType.RSA_4096:
modulus = 4096;
break;
default:
throw new ArgumentException("encryption");
}
KeyPair kp = null;
using (var rsa = new RSACryptoServiceProvider(modulus))
{
try
{
var privParams = rsa.ExportParameters(true);
var pubParams = rsa.ExportParameters(false);
var privBlob = rsa.ToXmlString(true);
var pubBlob = rsa.ToXmlString(false);
kp = new KeyPair
{
PrivKey = privBlob,
PubKey = pubBlob
};
}
catch (Exception)
{
throw;
}
finally
{
rsa.PersistKeyInCsp = false;
}
}
return kp;
}
示例9: Preferences
public Preferences()
{
_algorithm = EncryptionType.TripleDES;
_password = "abcdefgi";
_key = "abcdefghijklmnopqrstuvwx";
_defaultPath = "\\Windows\\SNOP";
_AskPassword = true;
}
示例10: MailConnection
public MailConnection(EncryptionType encryption, string server, int port, string username, string password)
{
_encryption = encryption;
_server = server.Trim();
_port = port;
_username = username.Trim();
_password = password.Trim();
}
示例11: Decrypt
/// <summary>
/// RC4-HMAC / RC4-HMAC-EXP decryption
/// </summary>
/// <param name="key">the secret key</param>
/// <param name="cipher">the encrypted cipher data</param>
/// <param name="usage">key usage number</param>
/// <param name="encryptionType">encryption type</param>
/// <returns>the decrypted data</returns>
public static byte[] Decrypt(
byte[] key,
byte[] cipher,
int usage,
EncryptionType encryptionType)
{
return Decrypt(key, cipher, usage, encryptionType, null);
}
示例12: frmProperties
public frmProperties(EncryptionType Type, String sPassword, String sKey, bool AskPass)
{
InitializeComponent();
_algorithm = Type;
_isCanceled = true;
_password = sPassword;
_key = sKey;
_askPassword = AskPass;
}
示例13: AmazonS3Synchronizer
/// <summary>
/// We-use the remote info as: accountName = awsAccessKeyId and accountKey = awsSecretAccessKey
/// </summary>
public AmazonS3Synchronizer(RemoteInfo remoteInfo, string bucket, SynchronizeDirection syncDirection, CompressionType compressionType, EncryptionType encryptionType, byte[] encryptionKey, byte[] initializationVector, Logger log, int ChunkSize, int ThreadPoolSize = 1 )
{
this.logger = log;
disposed = false;
this.syncDirection = syncDirection;
bucketName = bucket.ToString().Replace(' ', '-').ToLower(); ;// amazon S3 does not like spaces in bucket names
amazonS3Helper = new AmazonS3Helper(remoteInfo, bucket, compressionType, encryptionType, encryptionKey, initializationVector, logger, ChunkSize, ThreadPoolSize);
this.MaxConcurrentFileSyncThreads = ThreadPoolSize;
}
示例14: Server
/// <summary>
/// Allows adding a new server with the added option of specifying the encryption type if any and whether the server needs any authentication.
/// </summary>
/// <param name="host">Hostname/IP Address for server.</param>
/// <param name="port">Port to be used to connect to server.</param>
/// <param name="username">Username for authentication.</param>
/// <param name="password">Password for authentication.</param>
/// <param name="RequiresAuthentication">true if authentication is needed, false otherwise.</param>
/// <param name="EncType">Encryption type see EncryptionType enumeration.</param>
public Server(string host, int port, string username, string password,bool RequiresAuthentication, EncryptionType EncType)
{
this.Host = host;
this.Port = port;
this.Username = username;
this.Password = password;
_requiresAuthentication = RequiresAuthentication;
_encType = EncType;
}
示例15: Decrypt
public static byte[] Decrypt(byte[] encrypted, EncryptionType encType, string userPassword)
{
if (encType == EncryptionType.None)
return encrypted;
// Decrypt second pass (AES/PBKDF2)
byte[] secondPassDecrypt;
if (encType.HasFlag(EncryptionType.Password))
{
try
{
secondPassDecrypt = AESDecrypt(encrypted, userPassword);
}
catch (Exception) { return null; }
}
else
{
secondPassDecrypt = encrypted;
}
// Decrypt first pass (Machine/User Lock)
byte[] decrypted;
if (encType.HasFlag(EncryptionType.LocalUser) || encType.HasFlag(EncryptionType.LocalMachine))
{
try
{
decrypted = MachineDecrypt(secondPassDecrypt, encType);
}
catch (Exception) { return null; }
}
else
{
decrypted = secondPassDecrypt;
}
// Verify token signature
if (decrypted.Length != 30)
return null;
byte[] token = new byte[20];
Array.Copy(decrypted, token, 20);
byte[] signature = new byte[10];
Array.Copy(decrypted, 20, signature, 0, 10);
byte[] expectedSignature = SignToken(token);
if (expectedSignature.SequenceEqual(signature))
return token;
return null;
}