Click here to Skip to main content
15,891,722 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi! I am going to encrypt my password using hashing texhnique Argon2 i search a lot i found one script in asp.net c#,
How to Use Argon2 for Password Hashing in C# - Twelve 21[^]
but one i tried it gives me error.


Exception of type 'System.OutOfMemoryException' was thrown.

one thing the package in this article is

Konscious.Security.Cryptography

but that not supprted my .net framework the i instal this package

Konscious.Security.Cryptography.Argon2.StrongNamed

What I have tried:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Konscious.Security.Cryptography;

public partial class argon2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var password = "Hello World!";
        var salt = CreateSalt();
        var hash = HashPassword(password, salt);
        Response.Write(hash);



    }
    private byte[] CreateSalt()
    {
        var buffer = new byte[16];
        var rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
        rng.GetBytes(buffer);
        return buffer;
    }

    private byte[] HashPassword(string password, byte[] salt)
    {
        var argon2 = new Argon2d(Encoding.UTF8.GetBytes(password));

        argon2.Salt = salt;
        argon2.DegreeOfParallelism = 4; // four cores
        argon2.Iterations = 1;
        argon2.MemorySize = 1024 * 1024; // 1 GB

        return argon2.GetBytes(16);
    }
}
Posted
Updated 21-May-21 4:09am
v2

Since your code is all taken directly from your link, the best thing to do is to go back there and ask them: they have a comments forum at the end which will allow you to talk to the developer.
 
Share this answer
 
Comments
Jjopkjj 21-May-21 2:30am    
i am commented there but no one reply
OriginalGriff 21-May-21 4:02am    
How long did you give him to reply?

If it's over a week, then I'd find another source of information on how to do it, because that guy clearly isn't interested in anything except visits ... which makes his software really suspect ...
The hashing library you're using is broken. No other code in your sample would throw that exception.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900