public bool verifyPassword(string Password) { this.Password = Password; byte[] password = Utility.StringToByteArray(this.Password); Gost3411Digest digest = new Gost3411Digest(); SecureRandom random = new SecureRandom(); byte[] salt = random.GenerateSeed(16); digest.BlockUpdate(password, 0, password.Length); digest.BlockUpdate(salt, 0, 16); byte[] hash = new byte[digest.GetDigestSize()]; digest.DoFinal(hash, 0); return true; }
public BigInteger GetDigest(byte[] message) { Gost3411Digest gost3411Digest = new Gost3411Digest(); gost3411Digest.BlockUpdate(message, 0, message.Length); byte[] hashmessage = new byte[gost3411Digest.GetDigestSize()]; gost3411Digest.DoFinal(hashmessage, 0); return new BigInteger(hashmessage); }
private static byte[] computeHash3411(byte[] input) { Gost3411Digest digest = new Gost3411Digest(); byte[] output = new byte[GOST_3411_HASH_LENGTH]; digest.BlockUpdate(input, 0, input.Length); digest.DoFinal(output, 0); return output; }
private static string computeHash3411(string input) { Gost3411Digest digest = new Gost3411Digest(); byte[] output = new byte[GOST_3411_HASH_LENGTH]; byte[] bInput = Utility.StringToByteArray(input); digest.BlockUpdate(bInput, 0, bInput.Length); digest.DoFinal(output, 0); return Utility.ByteArrayToString(output); }
private byte[] generateKey(byte[] startkey) { byte[] newKey = new byte[Gost28147_KEY_LENGTH]; Gost3411Digest digest = new Gost3411Digest(); digest.BlockUpdate(startkey, 0, startkey.Length); digest.DoFinal(newKey, 0); return newKey; }
public LavaResult AddNewUser(LavaUser user) { LavaResult result = new LavaResult(); SqlConnection conn = new SqlConnection(connectionString); SqlCommand cmdNewCustomer = new SqlCommand("Volcano.uspNewUser", conn); cmdNewCustomer.CommandType = CommandType.StoredProcedure; cmdNewCustomer.Parameters.Add(new SqlParameter("@UserName", SqlDbType.NChar, 32)); cmdNewCustomer.Parameters["@UserName"].Value = user.UserName; byte[] password = Utility.StringToByteArray(user.Password); Gost3411Digest digest = new Gost3411Digest(); SecureRandom random = new SecureRandom(); byte[] salt = random.GenerateSeed(16); digest.BlockUpdate(password, 0, password.Length); digest.BlockUpdate(salt, 0, 16); byte[] hash = new byte[digest.GetDigestSize()]; digest.DoFinal(hash, 0); cmdNewCustomer.Parameters.AddWithValue("@Password", hash); cmdNewCustomer.Parameters.AddWithValue("@Salt", salt); cmdNewCustomer.Parameters.Add(new SqlParameter("@UserID", SqlDbType.Int)); cmdNewCustomer.Parameters["@UserID"].Direction = ParameterDirection.Output; try { conn.Open(); cmdNewCustomer.ExecuteNonQuery(); user.UserID = (int)cmdNewCustomer.Parameters["@UserID"].Value; } catch (SqlException sqlEx) { if (sqlEx.Errors.Count > 0) // Assume the interesting stuff is in the first error { switch (sqlEx.Errors[0].Number) { case 2627: // Foreign Key violation result.Result = LAVA_ERROR_CODE.USER_ALREADY_EXIST; result.Message = "UserName already exist. " + sqlEx.Message; break; default: result.Result = LAVA_ERROR_CODE.UNKNOWH_ERROR; result.Message = "Customer ID was not returned. Account could not be created. " + sqlEx.Errors[0].Number + sqlEx.Message; break; } } } catch (Exception ex) { result.Result = LAVA_ERROR_CODE.UNKNOWH_ERROR; result.Message = "Customer ID was not returned. Account could not be created. " + ex.Message; } finally { conn.Close(); } return result; }
/** * Test Sign and Verify with test parameters * see: http://www.ietf.org/internet-drafts/draft-popov-cryptopro-cpalgs-01.txt * gostR3410-2001-TestParamSet P.46 */ private void ecGOST3410_TestParam() { SecureRandom random = new SecureRandom(); BigInteger mod_p = new BigInteger("57896044618658097711785492504343953926634992332820282019728792003956564821041"); //p FpCurve curve = new FpCurve( mod_p, // p new BigInteger("7"), // a new BigInteger("43308876546767276905765904595650931995942111794451039583252968842033849580414")); // b ECDomainParameters parameters = new ECDomainParameters( curve, new FpPoint(curve, new FpFieldElement(mod_p,new BigInteger("2")), // x new FpFieldElement(mod_p,new BigInteger("4018974056539037503335449422937059775635739389905545080690979365213431566280"))), // y new BigInteger("57896044618658097711785492504343953927082934583725450622380973592137631069619")); // q ECKeyPairGenerator pGen = new ECKeyPairGenerator(); ECKeyGenerationParameters genParam = new ECKeyGenerationParameters( parameters, random); pGen.Init(genParam); AsymmetricCipherKeyPair pair = pGen.GenerateKeyPair(); ParametersWithRandom param = new ParametersWithRandom(pair.Private, random); ECGost3410Signer ecgost3410 = new ECGost3410Signer(); ecgost3410.Init(true, param); //get hash message using the digest GOST3411. byte[] message = Encoding.ASCII.GetBytes("Message for sign"); Gost3411Digest gost3411 = new Gost3411Digest(); gost3411.BlockUpdate(message, 0, message.Length); byte[] hashmessage = new byte[gost3411.GetDigestSize()]; gost3411.DoFinal(hashmessage, 0); BigInteger[] sig = ecgost3410.GenerateSignature(hashmessage); ecgost3410.Init(false, pair.Public); if (!ecgost3410.VerifySignature(hashmessage, sig[0], sig[1])) { Fail("signature fails"); } }
private bool VerifyGost(byte[] buffer, int length, byte[] signature) { ECDomainParameters dParams = ECGost3410NamedCurves.GetByOid(CryptoProObjectIdentifiers.GostR3410x2001CryptoProA); byte[] reversedPublicKey = PublicKey.Reverse().ToArray(); ECPoint q = dParams.Curve.CreatePoint(new BigInteger(1, reversedPublicKey, 32, 32), new BigInteger(1, reversedPublicKey, 0, 32), false); ECPublicKeyParameters parameters = new ECPublicKeyParameters(q, dParams); var signer = new ECGost3410Signer(); signer.Init(false, parameters); var digest = new Gost3411Digest(); digest.BlockUpdate(buffer, 0, length); byte[] hash = new byte[digest.GetDigestSize()]; digest.DoFinal(hash, 0); return signer.VerifySignature(hash, new BigInteger(1, signature, 32, 32), new BigInteger(1, signature, 0, 32)); }
private byte[] SignGost(byte[] buffer, int length) { ECGost3410Signer signer = new ECGost3410Signer(); signer.Init(true, new ParametersWithRandom(PrivateKeyFactory.CreateKey(PrivateKey), _secureRandom)); var digest = new Gost3411Digest(); digest.BlockUpdate(buffer, 0, length); byte[] hash = new byte[digest.GetDigestSize()]; digest.DoFinal(hash, 0); var signature = signer.GenerateSignature(hash); byte[] res = new byte[64]; signature[0].ToByteArrayUnsigned().CopyTo(res, 32); signature[1].ToByteArrayUnsigned().CopyTo(res, 0); return res; }