本文整理汇总了C#中EncryptionType.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# EncryptionType.ToString方法的具体用法?C# EncryptionType.ToString怎么用?C# EncryptionType.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EncryptionType
的用法示例。
在下文中一共展示了EncryptionType.ToString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EncryptWorkbook
public bool EncryptWorkbook(EncryptionType encryptionType, string password, int keyLength)
{
try
{
//build URI to get page count
string strURI = Product.BaseProductUri + "/cells/" + FileName + "/encryption";
string signedURI = Utils.Sign(strURI);
//serialize the JSON request content
Encryption encyption = new Encryption();
encyption.EncriptionType = encryptionType.ToString();
encyption.KeyLength = keyLength;
encyption.Password = password;
string strJSON = JsonConvert.SerializeObject(encyption);
Stream responseStream = Utils.ProcessCommand(signedURI, "POST", strJSON);
StreamReader reader = new StreamReader(responseStream);
string strResponse = reader.ReadToEnd();
//Parse the json string to JObject
JObject pJSON = JObject.Parse(strResponse);
BaseResponse baseResponse = JsonConvert.DeserializeObject<BaseResponse>(pJSON.ToString());
if (baseResponse.Code == "200" && baseResponse.Status == "OK")
return true;
else
return false;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
示例2: SendSspiAuthentication
private string SendSspiAuthentication () {
try {
// initialize network transport
TransportClient client =
new TransportClient(this.Repository.CvsRoot.ToString(),
typeof(CvsTransport));
this.SetInputStream(new CvsStream(client.GetStream()));
this.SetOutputStream(this.InputStream);
this.OutputStream.SendString("BEGIN SSPI\n");
string[] names = System.Enum.GetNames(typeof(EncryptionType));
string protocols = string.Empty;
for (int i = 0; i < names.Length; i++) {
protocols += names[i];
if (i + 1 < names.Length) {
protocols += ",";
}
}
this.OutputStream.SendString(string.Format("{0}\n", protocols));
string authTypeResponse = this.InputStream.ReadLine();
CurrentEncryptionType = (EncryptionType)
System.Enum.Parse(typeof(EncryptionType), authTypeResponse);
// initialize authorization module
authModule =
new NTAuthModule(new SecurityPackage(CurrentEncryptionType.ToString()));
// acquire client credentials
clientCredentials =
authModule.AcquireSecurityCredentials(SecurityCredentialsType.OutBound, null);
byte[] clientToken;
byte[] serverToken;
// create client context
SecurityContext clientContext =
authModule.CreateSecurityContext(clientCredentials,
SecurityContextAttributes.Identify, null, out clientToken);
while (true) {
if (clientToken != null) {
// send client token to server
string clientTokenString =
Encoding.ASCII.GetString(clientToken, 54, 57);
this.OutputStream.SendString(
clientTokenString);
}
if (clientContext.State == SecurityContextState.Completed) {
// authentication completed
break;
}
// receive server token
serverToken =
Encoding.ASCII.GetBytes(this.InputStream.ReadToFirstWS());
// update security context
authModule.UpdateSecurityContext(clientContext,
SecurityContextAttributes.Identify, serverToken, out clientToken);
}
// AuthenticateClient(client);
return InputStream.ReadLine();
} catch (IOException e) {
String msg = "Failed to read line from server. " +
"It is possible that the remote server was down.";
LOGGER.Error (msg, e);
throw new AuthenticationException (msg);
}
}
示例3: SetEncryptionType
/// <summary>
/// Set the <see cref="EncryptionType"/> and <see cref="_crypto"/> objects.
/// </summary>
/// <param name="encryptionType">Encryption type to be used.</param>
/// <param name="encryptionKey">If <paramref name="encryptionType"/> is a symmetric algorithm, this represents the encryption key to use.</param>
public static void SetEncryptionType(EncryptionType encryptionType, SecureString encryptionKey)
{
switch (encryptionType)
{
// Simply open or create an RSA key container called EasyConnect
case EncryptionType.Rsa:
CspParameters parameters = new CspParameters
{
KeyContainerName = "EasyConnect"
};
_crypto = new RSACryptoServiceProvider(parameters);
break;
// Initialize a Rijndael instance with the key in encryptionKey
case EncryptionType.Rijndael:
if (encryptionKey == null)
throw new ArgumentException("When Rijndael is used as the encryption type, the encryption password cannot be null.", "encryptionKey");
Rijndael rijndael = Rijndael.Create();
rijndael.KeySize = 256;
// Get the bytes for the password
IntPtr marshalledKeyBytes = Marshal.SecureStringToGlobalAllocAnsi(encryptionKey);
byte[] keyBytes = new byte[rijndael.KeySize / 8];
Marshal.Copy(marshalledKeyBytes, keyBytes, 0, Math.Min(keyBytes.Length, encryptionKey.Length));
// Set the encryption key to the key bytes and the IV to a predetermined string
rijndael.Key = keyBytes;
rijndael.IV = Convert.FromBase64String("QGWyKbe+W9H0mL2igm73jw==");
Marshal.ZeroFreeGlobalAllocAnsi(marshalledKeyBytes);
_crypto = rijndael;
break;
default:
throw new ArgumentException("The encryption type " + encryptionType.ToString("G") + " is not supported.", "encryptionType");
}
_encryptionType = encryptionType;
}
示例4: Connect
/// <summary>Connects to the directory server.
/// </summary>
/// <param name="encryptionType">Type of encryption to use for session</param>
public void Connect(EncryptionType encryptionType)
{
encryption = encryptionType;
if (encryption == EncryptionType.SSL)
conn.SecureSocketLayer = true;
conn.UserDefinedServerCertValidationDelegate += new
CertificateValidationCallback(SSLHandler);
conn.Connect (host, port);
if (encryption == EncryptionType.TLS) {
conn.startTLS ();
}
if (schemaDN == null)
schemaDN = "cn=subschema";
if (rootDN == null)
QueryRootDSE ();
Log.Debug ("Connected to '{0}' on port {1}", host, port);
Log.Debug ("Base: {0}", rootDN);
Log.Debug ("Using encryption type: {0}", encryptionType.ToString());
}