Konscious.Security.Cryptography icon indicating copy to clipboard operation
Konscious.Security.Cryptography copied to clipboard

System.Numerics.Vectors rears its ugly head (again)

Open Draco18s opened this issue 3 years ago • 2 comments

Also known as "#9 is back."

Ran into this a couple days ago having downloaded the NuGet packages Argon2 1.2.1 and Blake2 1.0.9 and got this error despite the fact that (a) this was fixed in 2017 and (b) the source still says v4.5 as a dependency. I fixed it by downgrading to 1.2.0 (tried literally every version of both Argon and Blake until it magically worked (!?) and then just now after mucking about with stuff it broke again.

Completely uninstalling everything including dependencies, then reinstalling 1.2.0 and 1.0.8 made it go away again (!?) even though a straight "install older version" didn't. I swear to god computers are built on black magic.

System.IO.FileLoadException: Could not load file or assembly 'System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at Konscious.Security.Cryptography.HMACBlake2B.CreateImplementation()
   at Konscious.Security.Cryptography.HMACBlake2B.Initialize()
   at Konscious.Security.Cryptography.HMACBlake2B.HashCore(Byte[] data, Int32 offset, Int32 size)
   at System.Security.Cryptography.HashAlgorithm.ComputeHash(Byte[] buffer)
   at net.novelai.api.Auth.CreateSalt(String saltin) in Auth.cs:line 41

My code:

	private static byte[] CreateSalt(string saltin) {
		byte[] bytes = new byte[saltin.Length];
		for(int i = 0; i < bytes.Length; i++) {
			bytes[i] = (byte)saltin[i];
		}
		HMACBlake2B encoder = new HMACBlake2B(bytes, 16);
		byte[] buffer = new byte[16];
		return encoder.ComputeHash(buffer);
	}

	public static byte[] HashArgon(int size, string plaintext, string secret, string domain) {
		var argon2 = new Argon2id(Encoding.UTF8.GetBytes(plaintext));
		argon2.Salt = CreateSalt(secret + domain);
		argon2.DegreeOfParallelism = 1;
		argon2.Iterations = 2;
		argon2.MemorySize = 2000000 / 1024;

		return argon2.GetBytes(size);
	}

Draco18s avatar Jul 18 '21 22:07 Draco18s

I am also having this issue, but following your workarounds i still cannot get it to work, it may be because I'm using Framework 4.6.

luhis avatar Nov 03 '21 15:11 luhis

I am also having this issue, but following your workarounds i still cannot get it to work, it may be because I'm using Framework 4.6.

It's the Black magic. Check this on your project. https://github.com/Draco18s/NovelAPI/blob/main/packages.config#L4-L5 No guarantees, but that project does compile.

Draco18s avatar Nov 03 '21 16:11 Draco18s