CryptoKey | A tool for generating keys using a CSPRNG

 by   AndrewCarterUK PHP Version: v0.2.0 License: MIT

kandi X-RAY | CryptoKey Summary

kandi X-RAY | CryptoKey Summary

CryptoKey is a PHP library. CryptoKey has no bugs, it has no vulnerabilities, it has a Permissive License and it has low support. You can download it from GitHub.

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

            kandi-support Support

              CryptoKey has a low active ecosystem.
              It has 50 star(s) with 4 fork(s). There are 1 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 1 open issues and 1 have been closed. There are no pull requests.
              It has a neutral sentiment in the developer community.
              The latest version of CryptoKey is v0.2.0

            kandi-Quality Quality

              CryptoKey has 0 bugs and 1 code smells.

            kandi-Security Security

              CryptoKey has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              CryptoKey code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              CryptoKey is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              CryptoKey releases are available to install and integrate.
              Installation instructions, examples and code snippets are available.
              CryptoKey saves you 49 person hours of effort in developing the same functionality from scratch.
              It has 130 lines of code, 9 functions and 3 files.
              It has medium code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed CryptoKey and discovered the below as its top functions. This is intended to give you an instant insight into CryptoKey implemented functionality, and help decide if they suit your requirements.
            • Configure the command .
            • Generate random data .
            Get all kandi verified functions for this library.

            CryptoKey Key Features

            No Key Features are available at this moment for CryptoKey.

            CryptoKey Examples and Code Snippets

            CryptoKey,Usage
            PHPdot img1Lines of Code : 8dot img1License : Permissive (MIT)
            copy iconCopy
            $ cryptokey generate
            bGS6lzFqvvSQ8ALbOxatm7/Vk7mLQyzqaS34Q4oR1ew=
            
            $ cryptokey generate --format=hex
            531a5187f08846a40ab6a9f9c651831bdd188e84b026804039773ef0aa51e500
            
            $ cryptokey generate --entropy=64
            ladkecOLF7RvMl/J5EGr/SMz5InfSyX+DA9CvecE/OiVFndnM  
            CryptoKey,An Alternative: OpenSSL
            PHPdot img2Lines of Code : 5dot img2License : Permissive (MIT)
            copy iconCopy
            $ openssl rand -base64 32
            3cDyOf7I6P4sU+ImVmIJW8k/IzGyoCACaJi+PbVY+I8=
            
            $ openssl rand -hex 32
            78a59462d4264e29be184226e7a46de0df96f97682963977fe61970b632d9faa
              
            CryptoKey,How To Install
            PHPdot img3Lines of Code : 2dot img3License : Permissive (MIT)
            copy iconCopy
            composer global require andrewcarteruk/cryptokey
            
            export PATH=~/.composer/vendor/bin:$PATH
              

            Community Discussions

            QUESTION

            AES-GCM needs the same init_vector from encryption FOR decryption. Why?
            Asked 2022-Apr-09 at 05:38

            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:38

            You 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.).

            Source https://stackoverflow.com/questions/71803634

            QUESTION

            Validating Firebase Auth tokens manually
            Asked 2022-Mar-28 at 23:43

            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:27

            There are a few issues with your code:

            1. 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.

            2. In importPublicKey you're telling the import method, that the key is in raw format and that it is an HMAC 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 using spki 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 the alg header claim)

            3. You're using sign method to verify the signature. That's not how it works. You should be using the verify method of crypto.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.

            Source https://stackoverflow.com/questions/71638739

            QUESTION

            Sign and verify JWS (json web signature) with Ed25519 KeyPair
            Asked 2022-Feb-17 at 20:49

            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:49

            You 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.

            Source https://stackoverflow.com/questions/68612396

            QUESTION

            Exporting a random RSA PublicKey from Java and importing it in JavaScript using Web Crypto
            Asked 2022-Jan-05 at 08:48

            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:48

            First 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:

            Source https://stackoverflow.com/questions/70587311

            QUESTION

            Using RSA to encrypt a message in JS and decrypt in Python
            Asked 2021-Dec-28 at 13:11

            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:11

            Directly 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.

            ...

            Source https://stackoverflow.com/questions/70507416

            QUESTION

            Reduce IO (Maybe (IO (Maybe a)) to IO (Maybe a)
            Asked 2021-Dec-22 at 09:17

            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:21

            Found 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:

            Source https://stackoverflow.com/questions/70445844

            QUESTION

            How to Decrypt AES SubtleCrypto Web API at SJCL Library
            Asked 2021-Dec-12 at 11:35

            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:35

            There 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:

            Source https://stackoverflow.com/questions/70321733

            QUESTION

            How to use KEYS.KEYSET_CHAIN in BigQuery
            Asked 2021-Dec-05 at 03:44

            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:44

            To 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:

            Source https://stackoverflow.com/questions/70200560

            QUESTION

            GCP Cloud KMS - custom key, disaster recovery possible?
            Asked 2021-Nov-29 at 10:39

            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

            1. 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:39

            Yes, 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.

            Source https://stackoverflow.com/questions/70123140

            QUESTION

            ECMAScript 8, async await, syntactical errors javascript
            Asked 2021-Nov-26 at 21:48

            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:31
            async 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();
            }
            

            Source https://stackoverflow.com/questions/70122081

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install CryptoKey

            Make sure you have added your global composer binary directory to the PATH in your ~/.bash_profile (or ~/.bashrc) file:. This blog explains the process of global composer installs in more detail.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/AndrewCarterUK/CryptoKey.git

          • CLI

            gh repo clone AndrewCarterUK/CryptoKey

          • sshUrl

            git@github.com:AndrewCarterUK/CryptoKey.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link