Array!string -> data compression -> Data Encryption -> Hash statement
Hi All, We have a requirement as below, and I tried the libraries such as std.digest, crypto, botan etc but no luck, hence request you suggestion's on how to achieve the below requirement. Array!string -> data compression -> Data Encryption -> Hash statement -> store the result in database table. From, Vino
Re: Encryption
On Monday, 17 May 2021 at 16:54:18 UTC, noid wrote: Hi! I am pretty new on Dlang and I wanted to make a small password manager that used some sort of encryption on a file (for example AES256) and save a password to decrypt it later, so you can copy the password. I haven't done this specifically myself, but if I did, I'd probably use bindings to the C libsodium and let it do most the encryption work. this looks reasonable but again I haven't used myself. https://code.dlang.org/packages/libsodiumd Since it is a simple binding to the C library, you'd use it the same way you would from C itself and can look up tutorials for that and easily translate to D. I also don't know how I could store the password (for example in a SHA256 hash) for decrypting the files. Now this I have done myself, and again, I delegated the real work to a C library called argon2. My library is https://code.dlang.org/packages/arsd-official%3Aargon2 And my docs: http://arsd-official.dpldocs.info/arsd.argon2.html If you get the C argon2 library installed, then you can use that D module easily with the `encode` and `verify` functions.
Re: Encryption
On Monday, 17 May 2021 at 17:08:41 UTC, noid wrote: On Monday, 17 May 2021 at 17:03:39 UTC, Imperatorn wrote: On Monday, 17 May 2021 at 16:54:18 UTC, noid wrote: Hi! I am pretty new on Dlang and I wanted to make a small password manager that used some sort of encryption on a file (for example AES256) and save a password to decrypt it later, so you can copy the password. I couldn't find any way of doing encryption on Dlang, is there a lib that's better for doing this? Secured and some other libs i tried didn't quite work. I also don't know how I could store the password (for example in a SHA256 hash) for decrypting the files. https://code.dlang.org/search?q=crypto crypto prints the error i just posted last post, botan lib gives me this error: Try different compiler options (version=??? to make the static assert true). If still not working, log an issue on the library's git repo page.
Re: Encryption
On Monday, 17 May 2021 at 16:59:28 UTC, mw wrote: On Monday, 17 May 2021 at 16:54:18 UTC, noid wrote: Hi! I am pretty new on Dlang and I wanted to make a small password manager that used some sort of encryption on a file (for example AES256) and save a password to decrypt it later, so you can copy the password. I couldn't find any way of doing encryption on Dlang, is there a lib that's better for doing this? Secured and some other libs i tried didn't quite work. I also don't know how I could store the password (for example in a SHA256 hash) for decrypting the files. https://code.dlang.org/search?q=SHA okay thanks i'll take a look at those libs but what about AES256? the crypto lib gave me some errors every time i ran "dub run" about the crypto lib "cannot call impure function 'core.bitop.volatileStore'"
Re: Encryption
On Monday, 17 May 2021 at 17:03:39 UTC, Imperatorn wrote: On Monday, 17 May 2021 at 16:54:18 UTC, noid wrote: Hi! I am pretty new on Dlang and I wanted to make a small password manager that used some sort of encryption on a file (for example AES256) and save a password to decrypt it later, so you can copy the password. I couldn't find any way of doing encryption on Dlang, is there a lib that's better for doing this? Secured and some other libs i tried didn't quite work. I also don't know how I could store the password (for example in a SHA256 hash) for decrypting the files. https://code.dlang.org/search?q=crypto crypto prints the error i just posted last post, botan lib gives me this error: ``` /home/anon/.dub/packages/memutils-1.0.4/memutils/source/memutils/utils.d:65:18: error: class botan.cert.x509.x509cert.X509CertificateImpl member init is not accessible 65 | return cast(TR)T.init; | ^ /home/anon/.dub/packages/memutils-1.0.4/memutils/source/memutils/utils.d:65:18: error: function botan.cert.x509.x509_obj.X509Object.init (RefCounted!(DataSourceImpl, AppMem) input, const(string) labels) is not callable using argument types () 65 | return cast(TR)T.init; | ^ /home/anon/.dub/packages/memutils-1.0.4/memutils/source/memutils/refcounted.d:31:52: error: template instance memutils.utils.ObjectAllocator!(X509CertificateImpl, ThreadMem).alloc!() error instantiating 31 | ret.m_object = ObjectAllocator!(T, ALLOC).alloc(args); |^ /home/anon/.dub/packages/memutils-1.0.4/memutils/source/memutils/refcounted.d:199:29: note: instantiated from here: opCall!() 199 |auto newObj = this.opCall(); | ^ /home/anon/.dub/packages/botan-1.12.19/botan/source/botan/cert/x509/x509cert.d:41:25: note: instantiated from here: RefCounted!(X509CertificateImpl, ThreadMem) 41 | alias X509Certificate = RefCounted!X509CertificateImpl; | ^ /home/anon/.dub/packages/botan-1.12.19/botan/source/botan/constants.d:98:73: error: static assert (BOTAN_HAS_SIMD) is false 98 | version(SIMD_SSE2) {enum BOTAN_HAS_SIMD_SSE2 = true; static assert(BOTAN_HAS_SIMD); } | ^ /usr/bin/gdc failed with exit code 1. ```
Re: Encryption
On Monday, 17 May 2021 at 16:54:18 UTC, noid wrote: Hi! I am pretty new on Dlang and I wanted to make a small password manager that used some sort of encryption on a file (for example AES256) and save a password to decrypt it later, so you can copy the password. I couldn't find any way of doing encryption on Dlang, is there a lib that's better for doing this? Secured and some other libs i tried didn't quite work. I also don't know how I could store the password (for example in a SHA256 hash) for decrypting the files. https://code.dlang.org/search?q=crypto
Re: Encryption
On Monday, 17 May 2021 at 16:54:18 UTC, noid wrote: Hi! I am pretty new on Dlang and I wanted to make a small password manager that used some sort of encryption on a file (for example AES256) and save a password to decrypt it later, so you can copy the password. I couldn't find any way of doing encryption on Dlang, is there a lib that's better for doing this? Secured and some other libs i tried didn't quite work. I also don't know how I could store the password (for example in a SHA256 hash) for decrypting the files. https://code.dlang.org/search?q=SHA
Encryption
Hi! I am pretty new on Dlang and I wanted to make a small password manager that used some sort of encryption on a file (for example AES256) and save a password to decrypt it later, so you can copy the password. I couldn't find any way of doing encryption on Dlang, is there a lib that's better for doing this? Secured and some other libs i tried didn't quite work. I also don't know how I could store the password (for example in a SHA256 hash) for decrypting the files.
Re: Question on Password Encryption, using stdlib or third party lib
On Monday, 29 July 2019 at 14:37:54 UTC, 0x wrote: On a project I was asked to a- Compute SHA-256 of a password b- Do a BigInteger, convert to Hex String c- Encrypt the key using a public key with the following parameters Entropy: I'm given some numbers Modulus: also given long numbers [encrypt using RSA algorithm] So far I'm familiar with a and b in Dlang. how do I go about c) In Dlang ? Thanks It is exponent not entropy
Re: Question on Password Encryption, using stdlib or third party lib
On Monday, 29 July 2019 at 14:37:54 UTC, 0x wrote: On a project I was asked to a- Compute SHA-256 of a password b- Do a BigInteger, convert to Hex String c- Encrypt the key using a public key with the following parameters Entropy: I'm given some numbers Modulus: also given long numbers [encrypt using RSA algorithm] So far I'm familiar with a and b in Dlang. how do I go about c) In Dlang ? Thanks I hope it's for a school project since I wouldn't recommend doing that in production. However you can do c) either by implementing RSA (it's rather easy to badly implement RSA which could be enough at school level) or by using a library (I recommend the library). There are several cryptographic libraries on https://code.dlang.org that implement RSA, botan and crypto for example. I'd trust botan more at the moment though I don't think any D library has received a proper cryptographic audit at the moment.
Question on Password Encryption, using stdlib or third party lib
On a project I was asked to a- Compute SHA-256 of a password b- Do a BigInteger, convert to Hex String c- Encrypt the key using a public key with the following parameters Entropy: I'm given some numbers Modulus: also given long numbers [encrypt using RSA algorithm] So far I'm familiar with a and b in Dlang. how do I go about c) In Dlang ? Thanks
Public private key encryption using existing key in dlang
Hi All, I have tried encrypting a message using public key and sending message to client, who decrypts using private key. I have tried with openssl d package. Below is my code. However it always fails in creating the context and exits by throwing exception. Key that i am using is RSA key. Please help me on this. I have also tried secured and crypto packages, but i see crash in these packages also. import std.array; import std.string; import std.algorithm; import std.stdio; import core.cpuid; import core.memory; import deimos.openssl.evp; import deimos.openssl.rand; import deimos.openssl.pem; import deimos.openssl.bio; import deimos.openssl.rsa; import deimos.openssl.engine; ubyte[] encrypt(const ubyte[] inMessage, EVP_PKEY* keypair) { ENGINE* eng = null; // Use default RSA implementation ubyte* out2; const ubyte* in2 = inMessage.ptr; size_t outlen; size_t inlen = inMessage.length; auto ctx = EVP_PKEY_CTX_new(keypair, eng); if (ctx == null) { throw new Exception("EVP_PKEY_CTX_new."); } scope (exit) { if (ctx !is null) { EVP_PKEY_CTX_free(ctx); } } if (EVP_PKEY_encrypt_init(ctx) <= 0) { if (!ctx) { throw new Exception("EVP_PKEY_CTX_new."); } } scope (exit) { if (ctx !is null) { EVP_PKEY_CTX_free(ctx); } } if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_OAEP_PADDING) <= 0) { throw new Exception("EVP_PKEY_CTX_set_rsa_padding failed."); } if (EVP_PKEY_encrypt(ctx, null, , in2, inlen) <= 0) { throw new Exception("EVP_PKEY_encrypt failed."); } out2 = cast(ubyte*) GC.malloc(outlen); if (out2 == null) { throw new Exception("Malloc failed."); } if (EVP_PKEY_encrypt(ctx, out2, , in2, inlen) <= 0) { throw new Exception("EVP_PKEY_encrypt failed."); } return (out2)[0 .. outlen]; } void main() { const(ubyte)[] message = cast(const(ubyte)[]) "Hello, this is a binary message!"; import core.stdc.stdlib : calloc, free; import std.base64; auto keyStr = "AAACANhbLxG1cezzbb/NsLQQSFseuOSKe2x7xcjuJmiiBC6tlbhT0RV6Y9Zad0tMp3OvS7etq0XRmeKK2QcP6gcqsVnOEX9qtPJMcGoyZxNo7nwU7DEyu9qEBhKMcI+jtRHEqcD0hGHgQg/KJ0bZsIFikKdezDSXQz8uVaJeypwkFChN auto keyBytes = Base64.decode(keyStr); // auto keyBytes = cast(ubyte[]) keyStr; auto bio = BIO_new_mem_buf(keyBytes.ptr, cast(int) keyBytes.length); auto keypair = PEM_read_bio_PUBKEY(bio, null, null, null); // auto rsaKey = PEM_read_bio_RSAPrivateKey(bio, null, null, null); BIO_free_all(bio); encrypt(message, keypair); }
Re: AES encryption with openssl bindings
AES_set_decrypt_key is needed before AES_decrypt. AES_set_decrypt_key(chunk.ptr, 128, wctx);
Re: AES encryption with openssl bindings
On Friday, 25 April 2014 at 19:06:33 UTC, brad clawsie wrote: My code compiles and fails silently. How do you want it to fail? C code doesn't throw exceptions.
AES encryption with openssl bindings
hi everyone. I'm trying to symmetrically encrypt some text using the openssl bindings. My code compiles and fails silently. Clearly there is something very wrong with it - it could be my novice D skills, or my misuse of the openssl binding. auto chunk = new ubyte[](16); foreach(ref x; chunk) x = uniform![](ubyte.min, ubyte.max); AES_KEY wctx; AES_set_encrypt_key(chunk.ptr,128,wctx); string s = virident; ubyte[] b; b = cast(ubyte[]) s; ubyte[] e; AES_encrypt(b.ptr,e.ptr,wctx); ubyte[] d; AES_decrypt(e.ptr,d.ptr,wctx); writefln(%s,d); Any clues? I am a D novice, so any spoonfeeding you could provide would be helpful :) thanks! Brad
Re: AES encryption with openssl bindings
On Fri, 25 Apr 2014 19:06:31 +, brad clawsie wrote: hi everyone. I'm trying to symmetrically encrypt some text using the openssl bindings. My code compiles and fails silently. Clearly there is something very wrong with it - it could be my novice D skills, or my misuse of the openssl binding. auto chunk = new ubyte[](16); foreach(ref x; chunk) x = uniform![](ubyte.min, ubyte.max); AES_KEY wctx; AES_set_encrypt_key(chunk.ptr,128,wctx); string s = virident; ubyte[] b; b = cast(ubyte[]) s; ubyte[] e; AES_encrypt(b.ptr,e.ptr,wctx); ubyte[] d; AES_decrypt(e.ptr,d.ptr,wctx); writefln(%s,d); Any clues? I am a D novice, so any spoonfeeding you could provide would be helpful :) thanks! Brad It doesn't look like you're allocating space for `e` or `d`, e.g. `auto e = new ubyte[](256);`, so those arrays have a length of 0, in which case the encrypt/decrypt functions are just trashing their way through memory.
Re: AES encryption with openssl bindings
Justin Whear: brad clawsie: b = cast(ubyte[]) s; Better to use std.string.representation. It doesn't look like you're allocating space for `e` or `d`, e.g. `auto e = new ubyte[](256);`, so those arrays have a length of 0, in which case the encrypt/decrypt functions are just trashing their way through memory. Thankfully we have slices in D. So better to write little wrapper functions, make them the only public functions in a module and use them only. Bye, bearophile