public ActionResult Register(Register register) { if (ModelState.IsValid) { try { ConnectUpdate udb = new ConnectUpdate(); hackathonunitecEntities db = udb.getDB(); user User = new user(); User.email = register.email; Crypto crypto = new Crypto(register.password); User.password = crypto.GetHash(); User.firstname = register.firstname; User.lastname = register.lastname; User.active = true; user_role User_Role = new user_role(); User_Role.roleid = 2; User_Role.active = true; User.user_role.Add(User_Role); db.user.Add(User); db.SaveChanges(); return View("Thanks"); } catch (Exception ex) { Console.Write(ex.ToString()); return View(); } } else { return View(); } }
private void ValidateSignature(string signature, string payload) { string matchingSignature = null; string[] signaturePairs = signature.Split('&'); foreach (string signaturePair in signaturePairs) { if (signaturePair.IndexOf('|') >= 0) { String[] candidatePair = signaturePair.Split('|'); if (Service.PublicKey.Equals(candidatePair[0])) { matchingSignature = candidatePair[1]; break; } } } Crypto crypto = new Crypto(); string computedSignature = crypto.HmacHash(Service.PrivateKey, payload).ToLower(); if (!crypto.SecureCompare(computedSignature, matchingSignature)) { throw new InvalidSignatureException(); } }
public ActionResult Login(Login login) { if (ModelState.IsValid) { ConnectUpdate udb = new ConnectUpdate(); hackathonunitecEntities db = udb.getDB(); Crypto crypto = new Crypto(login.password); string password = crypto.GetHash(); var users = db.user.Where(p => p.email == login.email && p.password == password ); int coun = users.Count(); if (users.Count() == 1) { Session["email"] = login.email; return View("Index"); } else { ModelState.AddModelError("email", "email or Password not valid"); return View(); } } else { return View(); } }
public void FunkyPasswords() { Crypto c = new Crypto(); { const string source = "antonida"; string s = c.Encrypt(source); Assert.AreNotEqual(source, s); Assert.AreEqual(source, c.Decrypt(s)); } { const string source = "привет мир"; string s = c.Encrypt(source); Assert.AreNotEqual(source, s); Assert.AreEqual(source, c.Decrypt(s)); } { const string source = @">rL`Fpbgr>_1j^?];cK5U>/!fm;&736puCLZeql=b-,-}rOdeR"; string s = c.Encrypt(source); Assert.AreNotEqual(source, s); Assert.AreEqual(source, c.Decrypt(s)); } { for (int i = 0; i < 1000; i++) { string source = RandomString(Math.Min(i + 1, 50)); string s = c.Encrypt(source); Assert.AreNotEqual(source, s); Assert.AreEqual(source, c.Decrypt(s)); } } }
private void Acceptbutton_Click(object sender, EventArgs e) { if (String.IsNullOrWhiteSpace(Username.Text) || String.IsNullOrWhiteSpace(Password.Text) || String.IsNullOrWhiteSpace(Host.Text)) { MessageBox.Show("Please fill out all values"); } else { String url = Host.Text; if (Uri.IsWellFormedUriString(url, UriKind.Absolute)) { Crypto crypto = new Crypto(); ConfigHandler ch = new ConfigHandler(); ch.SetConfig("ftpUserName", Username.Text); ch.SetConfig("ftpUrl", url); ch.SetConfig("ftpPassword", crypto.EncryptToString(Password.Text)); Close(); } else { MessageBox.Show("Hostname is not valid"); } } }
public static string MD5Crypto(string text) { Byte[] dataToHash = new Crypto().ConvertStringToByteArrayASCII(text); byte[] hashValue = (new MD5CryptoServiceProvider()).ComputeHash(dataToHash); //return hashValue.ToString(); return BitConverter.ToString(hashValue); }
public SolderSqlHandler() { Crypto crypto = new Crypto(); ConfigHandler ch = new ConfigHandler(); try { String s = ch.GetConfig("mysqlPassword"); if (String.IsNullOrWhiteSpace(s)) { ch.SetConfig("mysqlPassword", crypto.EncryptToString("password")); } } catch (Exception e) { Debug.WriteLine(e.Message); Debug.WriteLine(e.InnerException.ToString()); ch.SetConfig("mysqlPassword", crypto.EncryptToString("password")); } var password = crypto.DecryptString(ch.GetConfig("mysqlPassword")); var username = ch.GetConfig("mysqlUsername"); var address = ch.GetConfig("mysqlAddress"); _database = ch.GetConfig("mysqlDatabase"); _prefix = ch.GetConfig("mysqlPrefix"); _connectionString = String.Format("address={0};username={1};password={2};database={3}", address, username, password, _database); }
private void btnGuardarConexion_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (txtServer.Text != "" && txtDB.Text != "" && txtLogin.Text != "" && txtPassword.Text != "") { { SqlConnection conn = new SqlConnection("Data Source=" + txtServer.Text + ";Initial Catalog=" + txtDB.Text + ";Persist Security Info=True;User ID=" + txtLogin.Text + ";Password="******"AvoTrace", "ConexionSQL", "Server", EncriptarTexto.Encriptar(txtServer.Text)); RegIn.SaveSetting("AvoTrace", "ConexionSQL", "DBase", EncriptarTexto.Encriptar(txtDB.Text)); RegIn.SaveSetting("AvoTrace", "ConexionSQL", "User", EncriptarTexto.Encriptar(txtLogin.Text)); RegIn.SaveSetting("AvoTrace", "ConexionSQL", "Password", EncriptarTexto.Encriptar(txtPassword.Text)); RegIn.SaveSetting("AvoTrace", "ConexionSQL", "Sucursal", EncriptarTexto.Encriptar(Convert.ToString(cmbSucursal.SelectedValue))); RegIn.SaveSetting("AvoTrace", "ConexionSQL", "Estacion", EncriptarTexto.Encriptar(Convert.ToString(cbEstacion.SelectedValue))); MessageBox.Show("Se Grabaron los Datos Del Servidor Principal Con Exito"); this.Close(); } catch (Exception ex) { MessageBox.Show("Error Descripcion: " + ex); } } } else { MessageBox.Show("Faltan Datos para la Conexion Principal"); } }
public Token GetAuthenticationData() { var cookie = HttpContext.Current.Request.Cookies[WebAuthSettings.CookieKey]; if (cookie == null) { throw new WebAuthCookieNotFoundException(); } var crypto = new Crypto(); var tokenJs = crypto.DecryptStringAES(cookie.Value, WebAuthSettings.EncryptionSharedSecret); var token = (new JavaScriptSerializer()).Deserialize<Token>(tokenJs); if (token.Expiry < token.Time) { throw new TokenExpiredException(); } if (HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"] != token.UserIPAddress) { throw new InvalidIPException(); } return token; }
private bool PayloadMatches(string signature, string payload) { var sha1Hasher = new Sha1Hasher(); string computedSignature = sha1Hasher.HmacHash(service.PrivateKey, payload).ToLower(); var crypto = new Crypto(); return crypto.SecureCompare (computedSignature, signature); }
public void Sha1Bytes_ReturnsCorrectHash() { byte[] bytes = new Crypto().Sha1Bytes("hello world"); String hex = BitConverter.ToString(bytes); String actual = hex.Replace("-", ""); Assert.AreEqual("2AAE6C35C94FCFB415DBE95F408B9CE91EE846ED", actual); }
public static void doUserAndPassword() { string droneshareusername = MainV2.getConfig("droneshareusername"); InputBox.Show("Username", "Username", ref droneshareusername); MainV2.config["droneshareusername"] = droneshareusername; string dronesharepassword = MainV2.getConfig("dronesharepassword"); if (dronesharepassword != "") { try { // fail on bad entry var crypto = new Crypto(); dronesharepassword = crypto.DecryptString(dronesharepassword); } catch { } } InputBox.Show("Password", "Password", ref dronesharepassword,true); var crypto2 = new Crypto(); string encryptedpw = crypto2.EncryptString(dronesharepassword); MainV2.config["dronesharepassword"] = encryptedpw; }
public static void RegisterNewUser(Register regModel) { var cryptedPassword = new Crypto().Encrypt(regModel.Password); var newUser = new User {Email = regModel.Email, PasswordCrypted = cryptedPassword, UserName = regModel.Name}; Save(newUser); GalerieManager.CreateRootGallery(newUser); }
public registerForm() { regClient = new DBClient(); cryptSvc = new Crypto(); newCustomer = new Customer(); newAddress = new BillingAddress(); InitializeComponent(); }
public ChangePasswdDialog(String uName) { userName = uName; passwdPasses = false; pwdClient = new DBClient(); pwdCrypto = new Crypto(); InitializeComponent(); }
private static JArray GetDecryptedParamArray(string encryptedStr) { string passPhrase = AES_PASS_PHRASE; Crypto crypto = new Crypto(passPhrase); string clearData = crypto.DecryptFromBase64(encryptedStr); JArray paramArray = (JArray)JsonConvert.DeserializeObject(clearData); return paramArray; }
public Twitter() { Crypto decode_ = new Crypto(); if(!String.IsNullOrEmpty(Regedit.GetKey_("login_name"))) UserName = decode_.DecryptString(Regedit.GetKey_("login_name")); if (!String.IsNullOrEmpty(Regedit.GetKey_("login_pass"))) Password = decode_.DecryptString(Regedit.GetKey_("login_pass")); }
public void UseCustomKey() { const string S = "WqJCvfqa6JKiSXFm6t9MSAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="; Crypto c = new Crypto("my secret key"); string s = c.Encrypt("hello world"); Assert.AreNotEqual("hello world", s); Assert.AreEqual("hello world", c.Decrypt(s)); Assert.AreEqual("hello world", c.Decrypt(S)); }
public SqlInfo() { InitializeComponent(); Crypto crypto = new Crypto(); ConfigHandler ch = new ConfigHandler(); database.Text = ch.GetConfig("mysqlDatabase"); serveraddress.Text = ch.GetConfig("mysqlAddress"); password.Text = crypto.DecryptString(ch.GetConfig("mysqlPassword")); username.Text = ch.GetConfig("mysqlUsername"); Prefix.Text = ch.GetConfig("mysqlPrefix"); }
public void TestEncryptionAES() { var c = new Crypto(); string userKey = "4b236698-ebbb-4d3d-9513-961c5603d431"; string keySalt = "0000000001"; string text = "hello"; string cypher = c.Encrypt(text, userKey, keySalt); Console.WriteLine(cypher); string textdec = c.Decrypt(cypher, userKey, keySalt); Assert.AreEqual(text, textdec); }
private void DecryptButton_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(KeyBox.Text)) { MessageBox.Show("You must enter a key!"); } else { var crypto = new Crypto(KeyBox.Text); OutputBox.Text = crypto.Decrypt(InputBox.Text); } }
public string GetPassword(string name, string masterKey) { if (!ValidateMaster(masterKey)) throw new ArgumentException("Invalid Master Key."); var val = Passwords[name.ToLower()]; var crypto = new Crypto(); var result = crypto.DecryptStringFromBytes(Convert.FromBase64String(val.Item2), crypto.ConvertStringKey(masterKey), Convert.FromBase64String(val.Item1)); return result; }
public static Crypto Instance(string CertFile_Public,string CertFile_Private ,string password ) { if (_instance==null) { _instance= new Crypto() { CertFile_Public = CertFile_Public, CertFile_Private=CertFile_Private, Password = password }; } return _instance; }
public static string Decrypt(string string_to_decrypt) { if (string.IsNullOrWhiteSpace(string_to_decrypt)) return string.Empty; try { Crypto c = new Crypto(Crypto.CryptoTypes.encTypeTripleDES); return c.Decrypt(string_to_decrypt); } catch (Exception ex) { LogHelper.logError("Security.cs", "Unable to decrypt " + string_to_decrypt + " " + ex.Message + " " + ex.StackTrace); return ""; } }
private void S3Info_Load(object sender, EventArgs e) { try { ConfigHandler ch = new ConfigHandler(); Crypto crypto = new Crypto(); serviceURL.Text = ch.GetConfig("S3url"); accessKey.Text = crypto.DecryptString(ch.GetConfig("S3accessKey")); secretKey.Text = crypto.DecryptString(ch.GetConfig("S3secretKey")); } catch { // ignored } }
public static string Encrypt(string string_to_encrypt) { //I noticed a lot of this unable to encrypt message in the logs, I figured it would be best to silence this if (String.IsNullOrEmpty(string_to_encrypt)) return ""; try { Crypto c = new Crypto(Crypto.CryptoTypes.encTypeTripleDES); return c.Encrypt(string_to_encrypt); } catch (Exception ex) { LogHelper.logError("CryptoUtils.cs", "Unable to encrypt " + string_to_encrypt + " " + ex.Message + " " + ex.StackTrace); return ""; } }
/// <summary> /// Gets a pseudo-randomised interval for the next RTCP report period. /// </summary> /// <param name="baseInterval">The base report interval to randomise.</param> /// <returns>A value in milliseconds to use for the next RTCP report interval.</returns> private int GetNextRtcpInterval(int baseInterval) { return(Crypto.GetRandomInt((int)(RTCP_INTERVAL_LOW_RANDOMISATION_FACTOR * baseInterval), (int)(RTCP_INTERVAL_HIGH_RANDOMISATION_FACTOR * baseInterval))); }
public void EncryptShouldReturnCryptoMessage() { var mockedHelper = new Mock <ICryptoHelper>(); Crypto sut = new Crypto(mockedHelper.Object); }
public void Letters_are_lowercased_during_normalization() { var crypto = new Crypto("WHOA HEY!"); Assert.That(crypto.NormalizePlaintext, Is.EqualTo("whoahey")); }
public bool VerifyPassword(string actualPassword, string hashedPassword) { return(Crypto.VerifyHashedPassword(hashedPassword, actualPassword)); }
protected void PA812( ) { if (nDonePA == 0) { if (String.IsNullOrEmpty(StringUtil.RTrim(context.GetCookie("GX_SESSION_ID")))) { gxcookieaux = context.SetCookie("GX_SESSION_ID", Encrypt64(Crypto.GetEncryptionKey( ), Crypto.GetServerKey( )), "", (DateTime)(DateTime.MinValue), "", 0); } GXKey = Decrypt64(context.GetCookie("GX_SESSION_ID"), Crypto.GetServerKey( )); toggleJsOutput = isJsOutputEnabled( ); if (context.isSpaRequest( )) { disableJsOutput(); } init_web_controls( ); if (toggleJsOutput) { if (context.isSpaRequest( )) { enableJsOutput(); } } if (!context.isAjaxRequest( )) { } nDonePA = 1; } }
public static UInt160 ToScriptHash(this byte[] script) { return(new UInt160(Crypto.Hash160(script))); }
public void Size_is_determined_by_normalized_text() { var crypto = new Crypto("Oh hey, this is nuts!"); Assert.That(crypto.Size, Is.EqualTo(4)); }
public void Normalized_ciphertext_is_split_into_segements_of_correct_size() { var crypto = new Crypto("If man was meant to stay on the ground god would have given us roots"); Assert.That(crypto.NormalizeCiphertext(), Is.EqualTo("imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau")); }
public void Size_of_text_whose_length_is_not_a_perfect_square_is_next_biggest_square_root() { var crypto = new Crypto("123456789abc"); Assert.That(crypto.Size, Is.EqualTo(4)); }
public void Size_of_text_whose_length_is_a_perfect_square_is_its_square_root() { var crypto = new Crypto("123456789"); Assert.That(crypto.Size, Is.EqualTo(3)); }
public void Normalized_ciphertext_is_split_into_segements_of_correct_size_with_punctuation() { var crypto = new Crypto("Have a nice day. Feed the dog & chill out!"); Assert.That(crypto.NormalizeCiphertext(), Is.EqualTo("hifei acedl veeol eddgo aatcu nyhht")); }
public void Numbers_are_kept_during_normalization() { var crypto = new Crypto("1, 2, 3, GO!"); Assert.That(crypto.NormalizePlaintext, Is.EqualTo("123go")); }
public void TestCrypto_CheckMultiSig() { var engine = GetEngine(true); IVerifiable iv = engine.ScriptContainer; byte[] message = iv.GetHashData(); byte[] privkey1 = { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }; KeyPair key1 = new KeyPair(privkey1); ECPoint pubkey1 = key1.PublicKey; byte[] signature1 = Crypto.Sign(message, privkey1, pubkey1.EncodePoint(false).Skip(1).ToArray()); byte[] privkey2 = { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02 }; KeyPair key2 = new KeyPair(privkey2); ECPoint pubkey2 = key2.PublicKey; byte[] signature2 = Crypto.Sign(message, privkey2, pubkey2.EncodePoint(false).Skip(1).ToArray()); var pubkeys = new VMArray { pubkey1.EncodePoint(false), pubkey2.EncodePoint(false) }; var signatures = new VMArray { signature1, signature2 }; engine.CurrentContext.EvaluationStack.Push(signatures); engine.CurrentContext.EvaluationStack.Push(pubkeys); engine.CurrentContext.EvaluationStack.Push(StackItem.Null); InteropService.Invoke(engine, InteropService.Crypto.ECDsaCheckMultiSig).Should().BeTrue(); engine.CurrentContext.EvaluationStack.Pop().ToBoolean().Should().BeTrue(); pubkeys = new VMArray(); engine.CurrentContext.EvaluationStack.Push(signatures); engine.CurrentContext.EvaluationStack.Push(pubkeys); engine.CurrentContext.EvaluationStack.Push(StackItem.Null); InteropService.Invoke(engine, InteropService.Crypto.ECDsaCheckMultiSig).Should().BeFalse(); pubkeys = new VMArray { pubkey1.EncodePoint(false), pubkey2.EncodePoint(false) }; signatures = new VMArray(); engine.CurrentContext.EvaluationStack.Push(signatures); engine.CurrentContext.EvaluationStack.Push(pubkeys); engine.CurrentContext.EvaluationStack.Push(StackItem.Null); InteropService.Invoke(engine, InteropService.Crypto.ECDsaCheckMultiSig).Should().BeFalse(); pubkeys = new VMArray { pubkey1.EncodePoint(false), pubkey2.EncodePoint(false) }; signatures = new VMArray { signature1, new byte[64] }; engine.CurrentContext.EvaluationStack.Push(signatures); engine.CurrentContext.EvaluationStack.Push(pubkeys); engine.CurrentContext.EvaluationStack.Push(StackItem.Null); InteropService.Invoke(engine, InteropService.Crypto.ECDsaCheckMultiSig).Should().BeTrue(); engine.CurrentContext.EvaluationStack.Pop().ToBoolean().Should().BeFalse(); pubkeys = new VMArray { pubkey1.EncodePoint(false), new byte[70] }; signatures = new VMArray { signature1, signature2 }; engine.CurrentContext.EvaluationStack.Push(signatures); engine.CurrentContext.EvaluationStack.Push(pubkeys); engine.CurrentContext.EvaluationStack.Push(StackItem.Null); InteropService.Invoke(engine, InteropService.Crypto.ECDsaCheckMultiSig).Should().BeTrue(); engine.CurrentContext.EvaluationStack.Pop().ToBoolean().Should().BeFalse(); }
private Usuario AuthenticateUser(Usuario login) { login.Senha = Crypto.Criptografar(login.Senha, login.Email.Substring(0, 4)); return(_context.Usuario.Include(a => a.IdAcessoNavigation).FirstOrDefault(u => u.Email == login.Email && u.Senha == login.Senha)); }
public void Segments_are_split_by_square_size() { var crypto = new Crypto("Never vex thine heart with idle woes"); Assert.That(crypto.PlaintextSegments(), Is.EqualTo(new[] { "neverv", "exthin", "eheart", "withid", "lewoes" })); }
public string serialize() { var hex = Crypto.ByteArrayToHexString(this.value); return(Crypto.HexToVarBytes(hex)); }
public string HashPassword(string password) { return(Crypto.HashPassword(password)); }
public void Normalized_ciphertext_is_split_by_height_of_square() { var crypto = new Crypto("Vampires are people too!"); Assert.That(crypto.NormalizeCiphertext(), Is.EqualTo("vrel aepe mset paoo irpo")); }
public void Normalized_ciphertext_not_exactly_divisible_by_5_spills_into_a_smaller_segment() { var crypto = new Crypto("Madness, and then illumination."); Assert.That(crypto.NormalizeCiphertext(), Is.EqualTo("msemo aanin dnin ndla etlt shui")); }
public IUser EditUser(string username, string newUserName, string newPassword, string newAvatarPath, string newEmail, List <Tuple <IUser, bool> > users) { if (newEmail != "") { User.CanSetMail(newEmail); } if (newUserName != "") { User.CanSetUserName(newUserName); } if (newPassword != "") { User.CanSetPass(newPassword); newPassword = Crypto.Encrypt(newPassword); } //IUser ans= null; var query = db.Users.Where(u => u.Username == username); if (!query.Any()) { var e = new IllegalUsernameException("ERROR in Edit Profile: Username does not exist!"); Logger.Log(Severity.Error, e.Message); throw e; } var user = db.Users.First(u => u.Username == username); var foundUser = users.Single(t => t.Item1.Username == username); var ans = foundUser.Item1; if (!foundUser.Item2) { var e = new IllegalUsernameException("ERROR in Edit Profile: This User is not logged in."); Logger.Log(Severity.Error, e.Message); throw e; } try { if (newUserName != "" && newUserName != username) { query = db.Users.Where(u => u.Username == newUserName); if (query.Any()) { var e = new IllegalUsernameException("ERROR in Edit Profile: New username already exists!"); Logger.Log(Severity.Error, e.Message); throw e; } ans = new User(ans, newUserName); users.Remove(foundUser); db.Users.Remove(user); users.Add(new Tuple <IUser, bool>(ans, true)); foundUser = users.Single(t => t.Item1.Username == newUserName); db.Users.Add((User)ans); db.SaveChanges(); user = db.Users.First(u => u.Username == newUserName); //user.Username = newUserName; } if (newPassword != "") { ans.Password = newPassword; //check if it changes user.Password = newPassword; } if (newAvatarPath != "") { ans.AvatarPath = newAvatarPath; user.AvatarPath = newAvatarPath; } if (newEmail != "") { ans.Email = newEmail; user.Email = newEmail; } } catch (Exception ex) { var e = new Exception("ERROR in Edit Profile: Invalid new user details!" + ex.Message); Logger.Log(Severity.Error, e.Message); throw e; } //var userExists = false; //for (var i = 0; i < users.Count; i++) //{ // if (users[i].Item1.Username == username) // { // ans = users[i].Item1; // userExists = true; // if (!users[i].Item2) // { // var e = new IllegalUsernameException("ERROR in Edit Profile: This User is not logged in."); // Logger.Log(Severity.Error, e.Message); // throw e; // } // try // { // if (newUserName != null&&newUserName!=username) // { // for (var j = 0; j < users.Count; j++) // { // if (users[j].Item1.Username == newUserName) // { // var e = new IllegalUsernameException("ERROR in Edit Profile: New username already exists!"); // Logger.Log(Severity.Error, e.Message); // throw e; // } // } // users[i].Item1.Username = newUserName; // } // if (newPassword != null) // users[i].Item1.Password = newPassword; // if (newAvatarPath != null) // users[i].Item1.AvatarPath = newAvatarPath; // if (newEmail != null) // users[i].Item1.Email = newEmail; // } // catch (Exception) // { // var e = new Exception("ERROR in Edit Profile: Invalid new user details!"); // Logger.Log(Severity.Error, e.Message); // throw e; // } // } //} //if (!userExists) //{ // var e = new IllegalUsernameException("ERROR in Login: Username does not exist!"); // Logger.Log(Severity.Error, e.Message); // throw e; //} Logger.Log(Severity.Action, username + "'s profile edited successfully!"); db.SaveChanges(); return(ans); }
protected void send_integrity_footer_hashes( ) { GXKey = Decrypt64(context.GetCookie("GX_SESSION_ID"), Crypto.GetServerKey( )); }
public void Segments_are_split_by_square_size_until_text_runs_out() { var crypto = new Crypto("ZOMG! ZOMBIES!!!"); Assert.That(crypto.PlaintextSegments(), Is.EqualTo(new[] { "zomg", "zomb", "ies" })); }
public void Normalized_ciphertext_is_split_into_segements_of_correct_size_when_just_less_than_full_square() { var crypto = new Crypto("I am"); Assert.That(crypto.NormalizeCiphertext(), Is.EqualTo("im a")); }
internal static ECParameters GetECCurveParameters( SafeEcKeyHandle key, bool includePrivate) { ECCurve.ECCurveType curveType; SafeBignumHandle qx_bn, qy_bn, p_bn, a_bn, b_bn, gx_bn, gy_bn, order_bn, cofactor_bn, seed_bn, d_bn; int qx_cb, qy_cb, p_cb, a_cb, b_cb, gx_cb, gy_cb, order_cb, cofactor_cb, seed_cb, d_cb; int rc = AndroidCryptoNative_GetECCurveParameters( key, includePrivate, out curveType, out qx_bn, out qx_cb, out qy_bn, out qy_cb, out d_bn, out d_cb, out p_bn, out p_cb, out a_bn, out a_cb, out b_bn, out b_cb, out gx_bn, out gx_cb, out gy_bn, out gy_cb, out order_bn, out order_cb, out cofactor_bn, out cofactor_cb, out seed_bn, out seed_cb); using (qx_bn) using (qy_bn) using (p_bn) using (a_bn) using (b_bn) using (gx_bn) using (gy_bn) using (order_bn) using (cofactor_bn) using (seed_bn) using (d_bn) { if (rc == -1) { throw new CryptographicException(SR.Cryptography_CSP_NoPrivateKey); } else if (rc != 1) { throw new CryptographicException(); } int cbFieldLength; int pFieldLength; if (curveType == ECCurve.ECCurveType.Characteristic2) { // Match Windows semantics where a,b,gx,gy,qx,qy have same length // Treat length of m separately as it is not tied to other fields for Char2 (Char2 not supported by Windows) cbFieldLength = GetMax(new[] { a_cb, b_cb, gx_cb, gy_cb, qx_cb, qy_cb }); pFieldLength = p_cb; } else { // Match Windows semantics where p,a,b,gx,gy,qx,qy have same length cbFieldLength = GetMax(new[] { p_cb, a_cb, b_cb, gx_cb, gy_cb, qx_cb, qy_cb }); pFieldLength = cbFieldLength; } // Match Windows semantics where order and d have same length int cbSubgroupOrder = GetMax(order_cb, d_cb); // Copy values to ECParameters ECParameters parameters = default; parameters.Q = new ECPoint { X = Crypto.ExtractBignum(qx_bn, cbFieldLength), Y = Crypto.ExtractBignum(qy_bn, cbFieldLength) }; parameters.D = d_cb == 0 ? null : Crypto.ExtractBignum(d_bn, cbSubgroupOrder); var curve = parameters.Curve; curve.CurveType = curveType; curve.A = Crypto.ExtractBignum(a_bn, cbFieldLength) !; curve.B = Crypto.ExtractBignum(b_bn, cbFieldLength) !; curve.G = new ECPoint { X = Crypto.ExtractBignum(gx_bn, cbFieldLength), Y = Crypto.ExtractBignum(gy_bn, cbFieldLength) }; curve.Order = Crypto.ExtractBignum(order_bn, cbSubgroupOrder) !; if (curveType == ECCurve.ECCurveType.Characteristic2) { curve.Polynomial = Crypto.ExtractBignum(p_bn, pFieldLength) !; } else { curve.Prime = Crypto.ExtractBignum(p_bn, pFieldLength) !; } // Optional parameters curve.Cofactor = cofactor_cb == 0 ? null : Crypto.ExtractBignum(cofactor_bn, cofactor_cb); curve.Seed = seed_cb == 0 ? null : Crypto.ExtractBignum(seed_bn, seed_cb); parameters.Curve = curve; return(parameters); } }
public void Ciphertext_combines_text_by_column() { var crypto = new Crypto("First, solve the problem. Then, write the code."); Assert.That(crypto.Ciphertext(), Is.EqualTo("foeewhilpmrervrticseohtottbeedshlnte")); }
public void Ciphertext_skips_cells_with_no_text() { var crypto = new Crypto("Time is an illusion. Lunchtime doubly so."); Assert.That(crypto.Ciphertext(), Is.EqualTo("tasneyinicdsmiohooelntuillibsuuml")); }
/// <summary> /// Seeds the specified context. /// </summary> /// <param name="context">The context.</param> protected override void Seed(CloudNotesContext context) { #region Roles var administratorRole = new Role { Name = "Administrator", Description = "System administrator role that has the permission of all operations." }; context.Roles.Add(administratorRole); var accountManagerRole = new Role { Name = "Account Manager", Description = "Account Managers have the permission to create/update/delete the user accounts in CloudNotes system." }; context.Roles.Add(accountManagerRole); var packageManagerRole = new Role { Name = "Package Manager", Description = "Package Managers have the permission to post/get client packages." }; context.Roles.Add(packageManagerRole); #endregion #region Privileges var createUserPrivilege = new Privilege { Name = Privileges.ApiCreateUser, Description = "The create user privilege." }; context.Privileges.Add(createUserPrivilege); var updateUserPrivilege = new Privilege { Name = Privileges.ApiUpdateUser, Description = "The update user privilege." }; context.Privileges.Add(updateUserPrivilege); var pingPrivilege = new Privilege { Name = Privileges.ApiPing, Description = "Ping privilege." }; context.Privileges.Add(pingPrivilege); var getPackagePrivilege = new Privilege { Name = Privileges.ApiGetPackage, Description = "Get package privilege." }; context.Privileges.Add(getPackagePrivilege); var postPackagePrivilege = new Privilege { Name = Privileges.ApiPostPackage, Description = "Post package privilege." }; context.Privileges.Add(postPackagePrivilege); #endregion #region Permissions var adminCreateUserPermission = new Permission { Privilege = createUserPrivilege, Role = administratorRole, Value = PermissionValue.Allow }; context.Permissions.Add(adminCreateUserPermission); var adminPingPermission = new Permission { Privilege = pingPrivilege, Role = administratorRole, Value = PermissionValue.Allow }; context.Permissions.Add(adminPingPermission); var adminGetPackagePermission = new Permission { Privilege = getPackagePrivilege, Role = administratorRole, Value = PermissionValue.Allow }; context.Permissions.Add(adminGetPackagePermission); var adminPostPackagePermission = new Permission { Privilege = postPackagePrivilege, Role = administratorRole, Value = PermissionValue.Allow }; context.Permissions.Add(adminPostPackagePermission); var accountManagerCreateUserPermission = new Permission { Privilege = createUserPrivilege, Role = accountManagerRole, Value = PermissionValue.Allow }; context.Permissions.Add(accountManagerCreateUserPermission); var pkgManagerGetPackagePermission = new Permission { Privilege = getPackagePrivilege, Role = packageManagerRole, Value = PermissionValue.Allow }; context.Permissions.Add(pkgManagerGetPackagePermission); var pkgManagerPostPackagePermission = new Permission { Privilege = postPackagePrivilege, Role = packageManagerRole, Value = PermissionValue.Allow }; context.Permissions.Add(pkgManagerPostPackagePermission); #endregion #region Users var proxyUser = new User { DateRegistered = DateTime.UtcNow, UserName = Crypto.ProxyUserName, Email = Crypto.ProxyUserEmail, Password = Crypto.ComputeHash(Crypto.ProxyUserPassword, Crypto.ProxyUserName), Locked = true, Roles = new List <Role> { accountManagerRole, packageManagerRole } }; context.Users.Add(proxyUser); #endregion base.Seed(context); }
public void Smallest_square_size_is_2() { var crypto = new Crypto("1234"); Assert.That(crypto.Size, Is.EqualTo(2)); }
public static UInt160 ToScriptHash(this ReadOnlySpan <byte> script) { return(new UInt160(Crypto.Hash160(script))); }
public void Strange_characters_are_stripped_during_normalization() { var crypto = new Crypto("s#$%^&plunk"); Assert.That(crypto.NormalizePlaintext, Is.EqualTo("splunk")); }
protected void btnSubmit_Click(object sender, EventArgs e) { Crypto crypto = new Crypto(true); string plaintextToken = DateTime.Now.Ticks.ToString(); plaintextToken += " " + tbTerritories.Text; string encryptedToken = Server.UrlEncode(crypto.Encrypt(plaintextToken)); link.HRef = tbUrl.Text + "?token=" + encryptedToken; //Response.Redirect(tbUrl.Text + "?token=" + encryptedToken); }
private void SetUserAuthCookie() { Crypto crypto = new Crypto(); FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket(1, Session.SessionID, DateTime.Now, DateTime.Now.AddMinutes(FormsAuthentication.Timeout.Minutes), false, crypto.EncryptString(JsonConvert.SerializeObject(Session["Credencial"]))); string CookieString = FormsAuthentication.Encrypt(Ticket); HttpCookie Cookie = new HttpCookie(FormsAuthentication.FormsCookieName, CookieString); Cookie.Expires = Ticket.Expiration; Cookie.Path = FormsAuthentication.FormsCookiePath; Cookie.HttpOnly = true; System.Web.HttpContext.Current.Response.Cookies.Add(Cookie); }
private static JArray GetDecryptedJArrayParams(HttpContext context) { string message = context.Request.Params[METHOD_PARAMS.Message]; string passPhrase = AES_PASS_PHRASE; Crypto crypto = new Crypto(passPhrase); string clearData = crypto.DecryptFromBase64(message); JArray jsonArray = (JArray)JsonConvert.DeserializeObject(clearData); if (jsonArray.Count < 1) throw new Exception("Decrypted parameter list contains no paramater. "); return jsonArray; }
public S3() { ConfigHandler ch = new ConfigHandler(); Crypto crypto = new Crypto(); var accessKey = crypto.DecryptString(ch.GetConfig("S3accessKey")); var secretKey = crypto.DecryptString(ch.GetConfig("S3secretKey")); String url = ch.GetConfig("S3url"); _bucket = ch.GetConfig("S3Bucket"); var config = new AmazonS3Config {ServiceURL = url}; _client = AWSClientFactory.CreateAmazonS3Client(accessKey, secretKey, config) as AmazonS3Client; }