Пример #1
0
 public Argon2Result(string hash, string salt, Argon2Variant variant, uint iterations, uint memorySizeKiB, uint parallelism, uint derivedKeyLength)
 {
     Hash             = hash;
     Salt             = salt;
     Variant          = variant;
     Iterations       = iterations;
     MemorySizeKiB    = memorySizeKiB;
     Parallelism      = parallelism;
     DerivedKeyLength = derivedKeyLength;
 }
Пример #2
0
 public static Argon2Result ToBase64Argon2(string data, uint iterations, uint memorySizeKiB, uint parallelism, uint saltSize = Argon2SaltSize, Argon2Variant variant = Argon2Variant.Argon2id, uint derivedKeyLength = Argon2DerivedKeyLength)
 {
     byte[] salt = RandomManager.Next((int)saltSize);
     return(ToBase64Argon2(data, ToBase64(salt), true, iterations, memorySizeKiB, parallelism, variant, derivedKeyLength));
 }
Пример #3
0
 public static Argon2Result ToBase64Argon2(string data, string salt, bool isBase64Salt, uint iterations, uint memorySizeKiB, uint parallelism, Argon2Variant variant = Argon2Variant.Argon2id, uint derivedKeyLength = Argon2DerivedKeyLength)
 {
     return(new Argon2Result
            (
                hash: ToBase64(ToRawArgon2(ToByteArray(data), isBase64Salt ? FromBase64(salt) : ToByteArray(salt), iterations, memorySizeKiB, parallelism, variant, derivedKeyLength)),
                salt: isBase64Salt?salt: ToBase64(salt),
                variant: variant,
                iterations: iterations,
                memorySizeKiB: memorySizeKiB,
                parallelism: parallelism,
                derivedKeyLength: derivedKeyLength
            ));
 }
Пример #4
0
        public static byte[] ToRawArgon2(byte[] data, byte[] salt, uint iterations, uint memorySizeKiB, uint parallelism, Argon2Variant variant = Argon2Variant.Argon2id, uint derivedKeyLength = Argon2DerivedKeyLength)
        {
            switch (variant)
            {
            case Argon2Variant.Argon2d:
                Argon2d argon2d = new Argon2d(data);
                argon2d.Salt                = salt;
                argon2d.Iterations          = (int)iterations;
                argon2d.MemorySize          = (int)memorySizeKiB;
                argon2d.DegreeOfParallelism = (int)parallelism;
                return(argon2d.GetBytes((int)derivedKeyLength));

            case Argon2Variant.Argon2i:
                Argon2i argon2i = new Argon2i(data);
                argon2i.Salt                = salt;
                argon2i.Iterations          = (int)iterations;
                argon2i.MemorySize          = (int)memorySizeKiB;
                argon2i.DegreeOfParallelism = (int)parallelism;
                return(argon2i.GetBytes((int)derivedKeyLength));

            case Argon2Variant.Argon2id:
                Argon2id argon2id = new Argon2id(data);
                argon2id.Salt                = salt;
                argon2id.Iterations          = (int)iterations;
                argon2id.MemorySize          = (int)memorySizeKiB;
                argon2id.DegreeOfParallelism = (int)parallelism;
                return(argon2id.GetBytes((int)derivedKeyLength));

            default:
                throw new Exception("Invalid Argon2 variant");
            }
        }
Пример #5
0
 public static Argon2Result ToArgon2(this string data, IEncoder encoder, uint iterations, uint memorySizeKiB, uint parallelism, uint saltSize = Argon2SaltSize, Argon2Variant variant = Argon2Variant.Argon2id, uint derivedKeyLength = Argon2DerivedKeyLength)
 {
     byte[] salt = RandomManager.Next((int)saltSize);
     return(ToArgon2(data.ToByteArray(), salt, encoder, iterations, memorySizeKiB, parallelism, variant, derivedKeyLength));
 }
Пример #6
0
 public static Argon2Result ToArgon2(this string data, string salt, IEncoder encoder, uint iterations, uint memorySizeKiB, uint parallelism, Argon2Variant variant = Argon2Variant.Argon2id, uint derivedKeyLength = Argon2DerivedKeyLength)
 {
     return(ToArgon2(data.ToByteArray(), salt.ToByteArray(), encoder, iterations, memorySizeKiB, parallelism, variant, derivedKeyLength));
 }
Пример #7
0
 public static Argon2Result ToArgon2(this byte[] data, byte[] salt, IEncoder encoder, uint iterations, uint memorySizeKiB, uint parallelism, Argon2Variant variant = Argon2Variant.Argon2id, uint derivedKeyLength = Argon2DerivedKeyLength)
 {
     return(new Argon2Result
            (
                hash: encoder.Encode(ToArgon2(data, salt, iterations, memorySizeKiB, parallelism, variant, derivedKeyLength)),
                salt: encoder.Encode(salt),
                variant: variant,
                iterations: iterations,
                memorySizeKiB: memorySizeKiB,
                parallelism: parallelism,
                derivedKeyLength: derivedKeyLength,
                encoder: encoder
            ));
 }
Пример #8
0
        public static byte[] ToArgon2(this byte[] data, byte[] salt, uint iterations, uint memorySizeKiB, uint parallelism, Argon2Variant variant = Argon2Variant.Argon2id, uint derivedKeyLength = Argon2DerivedKeyLength)
        {
            switch (variant)
            {
            case Argon2Variant.Argon2d:
                Argon2d argon2d = new(data);
                argon2d.Salt                = salt;
                argon2d.Iterations          = (int)iterations;
                argon2d.MemorySize          = (int)memorySizeKiB;
                argon2d.DegreeOfParallelism = (int)parallelism;
                return(argon2d.GetBytes((int)derivedKeyLength));

            case Argon2Variant.Argon2i:
                Argon2i argon2i = new(data);
                argon2i.Salt                = salt;
                argon2i.Iterations          = (int)iterations;
                argon2i.MemorySize          = (int)memorySizeKiB;
                argon2i.DegreeOfParallelism = (int)parallelism;
                return(argon2i.GetBytes((int)derivedKeyLength));

            case Argon2Variant.Argon2id:
                Argon2id argon2id = new(data);
                argon2id.Salt                = salt;
                argon2id.Iterations          = (int)iterations;
                argon2id.MemorySize          = (int)memorySizeKiB;
                argon2id.DegreeOfParallelism = (int)parallelism;
                return(argon2id.GetBytes((int)derivedKeyLength));

            default:
                throw new NotImplementedException(variant.ToString());
            }
        }