private static string GetSignatureAlgorithm(SecurityKey key) { // If key is null, an exception is thrown. if (key == null) throw new ArgumentNullException("key"); // Set signatureAlgorithm to null. string signatureAlgorithm = null; // If the security key supports RsaSha1 then use that ... if (key.IsSupportedAlgorithm(SecurityAlgorithms.RsaSha1Signature)) signatureAlgorithm = SecurityAlgorithms.RsaSha1Signature; // ... otherwise if it supports HMACSha1 use that ... else if (key.IsSupportedAlgorithm(SecurityAlgorithms.HmacSha1Signature)) signatureAlgorithm = SecurityAlgorithms.HmacSha1Signature; return signatureAlgorithm; }
private static string GetEncryptionAlgorithm(SecurityKey key) { // If key is null, an exception is thrown. if (key == null) throw new ArgumentNullException("key"); // Set encryptionAlgorithm to null. string encryptionAlgorithm = null; // If the security key supports AES256 use that ... if (key.IsSupportedAlgorithm(SecurityAlgorithms.Aes256Encryption)) encryptionAlgorithm = SecurityAlgorithms.Aes256Encryption; // ... otherwise if it supports AES192 use that ... else if (key.IsSupportedAlgorithm(SecurityAlgorithms.Aes192Encryption)) encryptionAlgorithm = SecurityAlgorithms.Aes192Encryption; // ... otherwise if it supports AES128 use that ... else if (key.IsSupportedAlgorithm(SecurityAlgorithms.Aes128Encryption)) encryptionAlgorithm = SecurityAlgorithms.Aes128Encryption; return encryptionAlgorithm; }
private static string GetKeyWrapAlgorithm(SecurityKey key) { // If key is null, an exception is thrown. if (key == null) throw new ArgumentNullException("key"); // Set keywrapAlgorithm to null. string keywrapAlgorithm = null; // If the security key supports RsaOaep then use that ... if (key.IsSupportedAlgorithm(SecurityAlgorithms.RsaOaepKeyWrap)) keywrapAlgorithm = SecurityAlgorithms.RsaOaepKeyWrap; // ... otherwise if it supports RSA15 use that ... else if (key.IsSupportedAlgorithm(SecurityAlgorithms.RsaV15KeyWrap)) keywrapAlgorithm = SecurityAlgorithms.RsaV15KeyWrap; // ... otherwise if it supports AES256 use that ... else if (key.IsSupportedAlgorithm(SecurityAlgorithms.Aes256KeyWrap)) keywrapAlgorithm = SecurityAlgorithms.Aes256KeyWrap; // ... otherwise if it supports AES192 use that ... else if (key.IsSupportedAlgorithm(SecurityAlgorithms.Aes192KeyWrap)) keywrapAlgorithm = SecurityAlgorithms.Aes192KeyWrap; // ... otherwise if it supports AES128 use that ... else if (key.IsSupportedAlgorithm(SecurityAlgorithms.Aes128KeyWrap)) keywrapAlgorithm = SecurityAlgorithms.Aes128KeyWrap; return keywrapAlgorithm; }