/// <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()); }
public override string ToString() { string outString; outString = "SMTP Configuration:\n" + "MailServiceName: " + MailServiceName + "\n" + "MailServiceName: " + MailServiceName + "\n" + "SmtpServerAddress: " + SmtpServerAddress + "\n" + "SmtpServerPort: " + SmtpServerPort.ToString() + "\n" + "UserAccount: " + UserAccount + "\n" //+ "UserPassword: "******"\n" + "EncryptionType: " + EncryptionType.ToString() + "\n" ; return(outString); }
/// <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; }
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); } }
public static string BuildPacket(string source, string dest, string DataType, int sessionid, int processid, EncryptionType encryptiontype, Encoding encoding, byte[] Data, string NETNAME) { string contentb64 = Security.BToBase64(Data); StringBuilder SB = new StringBuilder(); // Append Source and Dest = 32 bytes in max SB.Append(source + "\r\n"); SB.Append(dest + "\r\n"); // Append Hash must be in 32 bytes SB.Append(Security.GetMd5Hashofstring(contentb64) + "\r\n"); // Append Data type, SID and PID SB.Append(DataType + "\r\n"); SB.Append(sessionid.ToString() + "\r\n"); SB.Append(processid.ToString() + "\r\n"); // Append Encryption Algorithm, Encoding, Signature SB.Append(encryptiontype.ToString() + "\r\n"); SB.Append(encoding.CodePage + "\r\n"); SB.Append(NETNAME + "\r\n"); // Append Data if (contentb64.Length > IPDTPRules.MaxContentSize) { return("FALSE"); } else { if (encryptiontype == EncryptionType.DECRYP) { SB.Append(contentb64); } else if (encryptiontype == EncryptionType.DPL128) { SB.Append(Security.Encrypt(contentb64)); } else { SB.Append(Security.EncryptTripleDES(contentb64, password)); } } return(Security.ToBase64(SB.ToString())); }
/// <summary> /// Returns an english human-readable display string for an encryption type /// </summary> /// <param name="encryptionType">type to get string for</param> /// <returns>string to display for the given type</returns> public static string ToDisplayString(this EncryptionType encryptionType) { switch (encryptionType) { case EncryptionType.AES_Legacy: return("AES (Legacy)"); case EncryptionType.AES_Bcrypt: return("AES (Bcrypt)"); case EncryptionType.BISS_1: return("BISS-1"); case EncryptionType.BISS_E: return("BISS-E"); case EncryptionType.TripleDES: return("Triple-DES"); default: return(encryptionType.ToString()); } }
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); } }
/// <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; }
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); } }
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); } }
/// <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()); }