本文整理汇总了C#中Crypto类的典型用法代码示例。如果您正苦于以下问题:C# Crypto类的具体用法?C# Crypto怎么用?C# Crypto使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Crypto类属于命名空间,在下文中一共展示了Crypto类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDecryptedJArrayParams
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;
}
示例2: SetUserAuthCookie
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);
}
示例3: SolderSqlHandler
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);
}
示例4: Sha1Bytes_ReturnsCorrectHash
public void Sha1Bytes_ReturnsCorrectHash()
{
byte[] bytes = new Crypto().Sha1Bytes("hello world");
String hex = BitConverter.ToString(bytes);
String actual = hex.Replace("-", "");
Assert.AreEqual("2AAE6C35C94FCFB415DBE95F408B9CE91EE846ED", actual);
}
示例5: MD5Crypto
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);
}
示例6: Login
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();
}
}
示例7: btnGuardarConexion_ItemClick
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=" + txtPassword.Text);
try
{
MSRegistro RegIn = new MSRegistro();
Crypto EncriptarTexto = new Crypto();
conn.Open();
RegIn.SaveSetting("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");
}
}
示例8: GetAuthenticationData
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;
}
示例9: doUserAndPassword
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;
}
示例10: Acceptbutton_Click
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");
}
}
}
示例11: ValidateSignature
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();
}
}
示例12: Register
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();
}
}
示例13: FunkyPasswords
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));
}
}
}
示例14: PayloadMatches
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);
}
示例15: RegisterNewUser
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);
}