Comments (21)
Sodium.KDF.Scrypt
is probably what you're looking for: https://github.com/charlesportwoodii/libsodium-uwp/blob/master/docs/KDF.md#scrypt-key-derivation. It implements crypto_pwhash_scryptsalsa208sha256
.
public static byte[] Sodium.KDF.Scrypt(string password, byte[] salt, PasswordHashOptions options)
libsodium
classifies is as a kdf within PasswordHash, hence the namespace difference.
from libsodium-uwp.
Ah yes it is, perfect thanks :)
from libsodium-uwp.
No problem. Let me know if you have any issues. The unit tests offer some good examples too: https://github.com/charlesportwoodii/libsodium-uwp/blob/master/Test/KDFTest.cs#L359
from libsodium-uwp.
Will do, thanks again
from libsodium-uwp.
I'm getting System.AccessViolationException exceptions thrown calling the PasswordHash and Kdf functions for Scrypt and Argon2i. Havent investigated yet. Am I missing something obvious?
Thanks,
Stuart
from libsodium-uwp.
Did you install from Nuget or source? If you installed from Nuget, have you added the ActivatableClass
stuff to your Package.appxmanifest
as outlined in the README?
Can you provide the full error message and the code you're using?
from libsodium-uwp.
Installed from Nuget
Yes, Ive included the config in Package.appxmanifest
Ive also referenced the VC++ 2015 runtime
For example:
function Hash(string source, byte[] salt)
{
var options = new Sodium.PasswordHashOptions
{
time_cost = 3,
memory_cost = 1 << 14
};
return Sodium.KDF.Argon2i(source, salt, options);
}
Exception:
An exception of type 'System.AccessViolationException' occurred ...
Message: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source: Sodium
from libsodium-uwp.
System.String
, not string
.
See the following example which I just confirmed works with rc1
from Nuget.
public MainPage()
{
this.InitializeComponent();
var password = "correct horse battery staple";
var salt = Sodium.Core.GetRandomBytes(32);
var hash = this.hash(password, salt);
// This works => System.Byte[] // 32 length
System.Diagnostics.Debug.WriteLine(hash);
}
/// <summary>
/// Hashes a password with Argon2i
/// </summary>
/// <param name="source">The password to hash</param>
/// <param name="salt">32 byte salt</param>
/// <returns>32 byte Argon2i hash of password</returns>
public byte[] hash(String source, byte[] salt)
{
var options = new Sodium.PasswordHashOptions
{
time_cost = 3,
memory_cost = 1 << 14
};
return Sodium.KDF.Argon2i(source, salt, options);
}
The underlying type that gets interpreted in C is Platform.String
, which corresponds to the C# System.String
type, not the native string
type.
Well, actually, it shouldn't matter whether you use System.String
or string
. The code above though works for UWP 10.
from libsodium-uwp.
Created a fresh project with the above.
Same problem :(
from libsodium-uwp.
Can you try including from source rather than from Nuget? What build of W10 are you targeting?
from libsodium-uwp.
Target version: Windows 10 Anniversary Edition (10.0; Build 14393)
Min Version: Windows 10 (10.0; Build 10586)
from libsodium-uwp.
Honestly, it sounds like the Package.appxmanifest
file doesn't have the extension information. Can you try referencing libsodium-uwp from source? If you clone libsodium-uwp
from source, do the unit tests run/pass?
Any chance you could upload your fresh project to Github? Bit easier to debug if I can see the entire picture.
from libsodium-uwp.
I downloaded the solution and tried a build from source but the build fails on the pre build event command. Its missing the libsodium source by the look of it.
from libsodium-uwp.
libsodium
proper is included as a submodule, you have to recursively clone the project to fetch it too.
git clone --recursive https://github.com/charlesportwoodii/libsodium-uwp
.
from libsodium-uwp.
Ah ok, sorry I just downloaded as zip.
from libsodium-uwp.
Build from source.
All tests pass except 1 - Argon2iTest - ArgumentException - Salt must be 16bytes in length.
from libsodium-uwp.
Replaced libsodium-uwp project reference with Nuget package reference.
Added the extension info to Package.appxmanifest.
Rerun tests.
5 tests failing and process ends with 'The active Test Run was aborted because the execution process exited unexpectedly'
from libsodium-uwp.
Pretty sure the Argon2i test has a typo, it should use a 16 instead of 32 for the salt generation. I've updated that in the Git repo. If you git pull
then rebuild it should pass.
It sounds like the Nuget package might be bugged (or for some reason you're getting an older version). If you pull the tests should all pass, then you can include the project in your main project as a source reference rather than a Nuget reference.
from libsodium-uwp.
No worries I'll do that. Thanks for your help.
from libsodium-uwp.
@globeport Including from source work for you?
from libsodium-uwp.
So far so good...
from libsodium-uwp.
Related Issues (20)
- ChaCha20 Stream Cipher
- XSalsa20 Stream Cipher HOT 1
- OneTime Authentication
- HMAC-SHA-2
- CryptoHash.Hash
- Password Hashing HOT 1
- ShortHash
- GenericHash HOT 1
- Will this run on Raspberry Pi / Windows 10 IoT Core? HOT 1
- [KDF:Argon2i/Scrypt] on x64 |System.AccessViolationException HOT 23
- Compile error after upgrading to 1.0.131 HOT 7
- RANDOMBYTES_DEFAULT_IMPLEMENTATION macro redefinition
- Build against vsc++std:latest C++ toolchain
- Add pre build task to detect if ADVAPI32.dll or GenRandom function will be included
- Question: Can I use this from a C++ UWP? HOT 2
- Compiling with ARM or x64 as target HOT 3
- Detached Secret Boxes HOT 1
- Detached Public Key Boxes
- Detached Public Key Signatures
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libsodium-uwp.