bitwiseshiftleft / sjcl

Stanford Javascript Crypto Library
http://bitwiseshiftleft.github.com/sjcl/
Other
7.18k stars 986 forks source link

How to create simple license key #389

Open cowboychicken opened 5 years ago

cowboychicken commented 5 years ago

Hello!

Would it be possible to create a simple license key generator/validator using this library?

I am currently working on a school project that deals with locking down features (of a program/product) and requiring users to enter license keys to unlock them.

My specific task for this project is to find a way to generate license keys from a given bit string that can later be validated on the client side.

I’ve started by hacking apart the provided example/demo because the ‘Key’ that gets generated when a ‘Password’ and ‘Plaintext’ is provided appears to be what I am looking for. I have since able to generate keys from specific passwords by using the provided ‘doEncrypt()’ method (from example.js) and by passing in an empty string as my plaintext and salt.

p = { adata: v.adata, iter: v.iter, mode: v.mode, ts: parseInt(v.tag), ks: parseInt(v.keysize) };

p.salt = ""; ct = sjcl.encrypt(key, "", p, rp).replace(/,/g, ",\n"); v.key = rp.key;

However, I cannot figure out how to retrieve the corresponding password when only a key is provided.

I realize this is probably a haphazard way of going about this all so any advice/guidance would be very much appreciated!