Sphereon-Opensource / isomorphic-argon2

Argon2 hash library for Browser, NodeJs and React-Native
Apache License 2.0
3 stars 1 forks source link

Argon2 hash not working on react native #2

Open Eldii opened 1 year ago

Eldii commented 1 year ago

I get the following error when I try to hash a password : [Error: src.length=12 srcPos=-20 dst.length=32 dstPos=0 length=32]

Here is my code :

import { Argon2, Argon2Mode } from '@sphereon/isomorphic-argon2';

export async function hash(password, salt, hashLength, memory, parallelism, iterations) {
    try {
      const { encoded } = await argon2.hash(
        password,
        salt,
        {
          hashLength,
          memory,
          parallelism,
          mode: Argon2Mode.Argon2i,
          iterations,
        },
      );
      return encoded;
    } catch (error) {
      console.error(error);
    }
  }

Does it mean something to you ?

Thanks by advance

pikami commented 1 month ago

@Eldii I had the same issue, after some investigation I found that the native code expects the "salt" to be a hex string of at least 32 bytes (64 characters). Here's an example of a value that will work "a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3".