Why are the RSA-SHA256 signatures I generate with OpenSSL and Java different?

openssl dgst -sha256 < data.txt produces something like: (stdin)= b39eaeb437e33087132f01c2abc60c6a16904ee3771cd7b0d622d01061b40729 notice the (stdin)=‘? you don’t want that to be part of your hash, if you need to create a digest, use the -binary option. try using this to sign your data: openssl sha -sha256 -sign private.pem < data.txt This does everything you need. edit – … Read more

Encrypting/Decrypting large files (.NET)

One organism’s large is another’s petite, though we all know expensive when we see it. Wink, wink. Try benchmarking something like the following in your environment and see where you’re at: EDIT 2/13/2012: The code has been updated as I’ve become (imperceptibly) smarter and also noticed a few cut’n’paste errors that had crept in. Mea … Read more

How to generate RSA private key using OpenSSL?

#include <openssl/rsa.h> #include <openssl/pem.h> const int kBits = 1024; const int kExp = 3; int keylen; char *pem_key; RSA *rsa = RSA_generate_key(kBits, kExp, 0, 0); /* To get the C-string PEM form: */ BIO *bio = BIO_new(BIO_s_mem()); PEM_write_bio_RSAPrivateKey(bio, rsa, NULL, NULL, 0, NULL, NULL); keylen = BIO_pending(bio); pem_key = calloc(keylen+1, 1); /* Null-terminate */ BIO_read(bio, … Read more

RSA Encryption with given public key (in Java)

Here’s how I manage to encrypt a string with only a RSA public key. First save the public key in PEM-format to the filename pubkey.pem —–BEGIN PUBLIC KEY—– AJOnAeTfeU4K+do5QdBM2BQUhfrRI2rYf/Gk4… —–END PUBLIC KEY—– Find the public RSA key modulus $ openssl rsa -pubin -in pubkey.pem -modulus -noout Modulus=F56D… Find the public RSA key Exponent $ openssl … Read more

RSA public/private keys in YAML

You can store your keys as text (“ASCII-armored” / base 64 encoded). From Wikipedia, the syntax for multiline strings in YAML is: – title: An example multi-line string in YAML body : | This is a multi-line string. “special” metacharacters may appear here. The extent of this string is indicated by indentation.

How to sign a JWT using RS256 with RSA private key

I know this post is old, but it took me forever to figure this out, so I thought I would share. To test I created RSA keys using OpenSSL: openssl genrsa -out privateKey.pem 512 openssl rsa -in privateKey.pem -pubout -out publicKey.pem You will need the following 2 nuget packages: https://github.com/dvsekhvalnov/jose-jwt http://www.bouncycastle.org/csharp/ Test Code public static … Read more

tech