CryptoKey | A tool for generating keys using a CSPRNG
kandi X-RAY | CryptoKey Summary
kandi X-RAY | CryptoKey Summary
A tool for generating keys using a CSPRNG. If you have OpenSSL installed read below, as you probably do not need to install this tool.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Configure the command .
- Generate random data .
CryptoKey Key Features
CryptoKey Examples and Code Snippets
$ cryptokey generate
bGS6lzFqvvSQ8ALbOxatm7/Vk7mLQyzqaS34Q4oR1ew=
$ cryptokey generate --format=hex
531a5187f08846a40ab6a9f9c651831bdd188e84b026804039773ef0aa51e500
$ cryptokey generate --entropy=64
ladkecOLF7RvMl/J5EGr/SMz5InfSyX+DA9CvecE/OiVFndnM
$ openssl rand -base64 32
3cDyOf7I6P4sU+ImVmIJW8k/IzGyoCACaJi+PbVY+I8=
$ openssl rand -hex 32
78a59462d4264e29be184226e7a46de0df96f97682963977fe61970b632d9faa
composer global require andrewcarteruk/cryptokey
export PATH=~/.composer/vendor/bin:$PATH
Community Discussions
Trending Discussions on CryptoKey
QUESTION
I've created a TypeScript example from MDN example as verbatim as I could to illustrate. It encrypts and decrypts just fine. I just noticed that, for Decryption to work, it requires the same init_vector
from encryption. Isn't the init_vector
supposed to be a nonce?
How is the person receiving the message going to know what the init_vector
I've used for encryption if decryption is a separate process done at a different place and time?
ANSWER
Answered 2022-Apr-09 at 05:38You should use asymmetric encryption like RSA which has a public / private key, for example this node-rsa package.
In terms of having the same initial vector, I found this snippet taken from this answer:
In any case, the IV never needs to be kept secret — if it did, it would be a key, not an IV. Indeed, in most cases, keeping the IV secret would not be practical even if you wanted to since the recipient needs to know it in order to decrypt the data (or verify the hash, etc.).
QUESTION
I'm trying to use cloudflare workers to perform authenticated actions.
I'm using firebase for authentication and have access to the Access Tokens coming through but since firebase-admin uses nodejs modules it can't work on the platform so i'm left manually validating the token.
I've been attempting to authenticate with the Crypto API and finally got it to import the public key sign the token to check if its valid but I keep getting FALSE. I'm struggling to figure out why its always returning false for validity.
The crypto key I imported is coming in as type "secret" where I would expect it to be "public".
Any thoughts or assistance would be huge. Been banging my head against a table for the last couple of days trying to figure this out
This is what I have so far:
...ANSWER
Answered 2022-Mar-28 at 15:27There are a few issues with your code:
The URL you call to obtain public keys returns a list of x509 certificates. These are not public keys used to verify signatures. Are you sure you don't have access directly to the public keys? It seems like it's possible to get the public key information from an x509 certificate (as described here: Extract PEM Public Key from X.509 Certificate), though I'm not sure whether that's possible from a Cloudflare worker.
In
importPublicKey
you're telling theimport
method, that the key is in raw format and that it is anHMAC
key. This means that crypto treats your key as a symmetric HMAC key, not as a public key. According to the docs: https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey#subjectpublickeyinfo you should be usingspki
format as this is the one to import a public key. You would have to know up front whether the JWT access token is signed using RSA or Elliptic Curve algorithm. (e.g. check thealg
header claim)You're using
sign
method to verify the signature. That's not how it works. You should be using theverify
method ofcrypto.subtle
and this method will verify the signature for you.
I think you shouldn't be trying to verify JWTs manually, as you will most probably do it wrong (and create security issues for your app). You should be using libraries that deal with the verification of JWT signatures. It will be much easier for you and more secure for your app. One thing you have to figure out is to where you should take the public key from.
QUESTION
I want to sign a JWS (json web signature) with a private key generated through Ed25519 on a clients device. Then send this signature to my backend and verify it with the public key.
To get familiar with the procedure I want to try to sign and verify a JWS in node js.
Both my private and public key are already generated and are available in base58. This is my current attempt at signing a JWT with an Ed25519 privateKey:
ANSWER
Answered 2022-Feb-17 at 20:49You need your keys in a format that Node.js recognizes. KeyObject create*Key APIs recognize and the key is supported in - for Ed25519 keys that is, assuming Node.js >= 16.0.0:
- PEM/DER in SPKI for public keys
- PEM/DER in PKCS8 for private keys
- JWK for both public and private keys
Here's a snippet that uses DER.
QUESTION
I am able to transfer a byte array from a Java server to a JavaScript server (is received as an Int32Array). With this, I want to be able to transfer a PublicKey generated in Java and receive it as a CryptoKey in JavaScript.
The RSA Public key is generated in Java like so:
...ANSWER
Answered 2022-Jan-05 at 08:48First of all a working solution: The DER encoded X.509/SPKI key generated with Key#getEncoded()
is Base64 encoded and then imported to the JavaScript side as follows:
QUESTION
I want to encrypt a message using RSA with a provided PEM public key in Javascript, using SubtleCrypto window.crypto.subtle
and then decode it with Python (PyCryptodome) in the back-end. However, I get a ValueError: Incorrect decryption.
. I'm not sure if the data is being correctly handled though. Here is my code:
JavaScript:
...ANSWER
Answered 2021-Dec-28 at 13:11Directly from the documentation of Crypto.Cipher.PKCS1_OAEP.new(key, hashAlgo=None, mgfunc=None, label='', randfunc=None)
:
...
hashAlgo
(hash object) - The hash function to use. This can be a module under Crypto.Hash or an existing hash object created from any of such modules. If not specified, Crypto.Hash.SHA1 is used....
QUESTION
I have a function that reads an Rsa key with the HsOpenSsl's readPrivateKey
function unfortunately the signature of my function is this String -> IO (Maybe (IO Maybe RsaKey))
. I need the PEM format and a Cryptonite.RSA key and I wrote the function mkRsaKey
to make that from a string in PEM format.
Heres the code:
...ANSWER
Answered 2021-Dec-22 at 08:21Found a way to do it without unsafePerformIO
the trick is to use a case statement which only uses the return function in the Nothing
case. Here's the implementation:
QUESTION
We have an Expo React Native Project utilizing encryption. Our current encryption is based on SubtleCrypto / Web API [window.subtle.crypto], using AES-GCM 128, now we need to use a library that is universally available on all platforms [Web, iOS and Android], from my previous question, we've found SJCL that supports GCM mode and we can completely replace all the web-only based code BUT the challenge is that we need to ensure that all the current encrypted data is decrypted at this new library too, we have to make it so:
window.crypto.subtle.encrypt [AES-GCM 128] => (a) ---> SJCL.mode.gcm.decrypt(a)
Once we can do that successfully, we can fully replace the library and have universal platform support as well as backwards compatibility.
This means that we cannot change the way encryption is handled at all, as that is the requirement, and we're encrypting it exactly as the code below.
I got a very good lead here by Neneil94 but I'm still facing issues at encoding / formats; and here's the current code:
...ANSWER
Answered 2021-Dec-12 at 11:35There are two problems in your code:
kkey
is the Base64url encoded raw key. This must first be converted to Base64 and then to a bitArray:
QUESTION
I'm trying to use KEYS.KEYSET_CHAIN to obtain the a key from the KMS but I haven't figured out how to generate the first_level_keyset correctly. I'm getting the following message:
AEAD.ENCRYPT failed: Keyset deserialization failed: Error reading keyset data: Could not parse the input stream as a Keyset-proto.
I'm following the doc:
My code:
...ANSWER
Answered 2021-Dec-05 at 03:44To generate the first_level_keyset
, you will need to:
1.-Create a Key Management Service
. Users need to have the cloudkms.cryptoKeyDecrypterViaDelegation
role.
2.-Create a raw keyset.You need to execute the next command at cloud shell:
QUESTION
we are currently getting our heads around gcp cloud kms and how to cater for disaster recovery. this is our current test setup:
Java using Spring boot + Google Tink using KMSEnvelopeAead + AesGcmJce (i.e. generated DEK by tink that will be encrypted via kms (KEK) and stored alongside the ciphertext), symmetric
project "A" (the initial project before disaster recovery)
-> KMS -> keyring "keyringABC" -> key "keyABC" -> imported custom key via import job. i can successfully encrypt/decrypt some text - all fine, all good
ANSWER
Answered 2021-Nov-29 at 10:39Yes, it has to be the exact same key with the exact same resource id including project id.The ciphertext for decryption should be exactly as returned from the encrypt call. So, you need to make sure it matches the project in which you created the KMS key. When you try to decrypt the data with the newly created key from project-B that was encrypted in project-A, it fails.
In your use-case the ciphertext you're trying to decrypt was encrypted using a different key. You should use the same key for both encryption and decryption, else KMS tells you that it could not find the key while actually the key was found.
QUESTION
using more then one async()
in a chain in the function breaks my function.
Is there a way i can include Key2pkcs8()
inside generateKey()
?
ANSWER
Answered 2021-Nov-26 at 10:31async function generateKey() {
let keyPair = await crypto.subtle.generateKey(
{
name: "ECDH",
namedCurve: "P-384"
},
false,
["deriveKey"]
);
let PriKey = (keyPair) => {
let PriKey = keyPair.privateKey;
console.log("pri = " + PriKey);
return keyPair;
};
let PubKey = (keyPair) => {
let PubKey = keyPair.publicKey;
console.log("pub = " + PubKey);
return keyPair;
};
let Key2pkcs8 = async(keyPair) => {
console.log("key = " + keyPair);
let Key2pkcs8 = await crypto.subtle.exportKey("pkcs8", keyPair);
return Key2pkcs8;
};
let printme = async() => {
let printme = await Key2pkcs8(PubKey());
console.log(printme);
return printme;
};
return printme();
}
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install CryptoKey
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page