gocrypto | Example source code for the Practical Crypto with Go book | Cryptography library

 by   kisom Go Version: Current License: ISC

kandi X-RAY | gocrypto Summary

kandi X-RAY | gocrypto Summary

gocrypto is a Go library typically used in Security, Cryptography, Bitcoin applications. gocrypto has no bugs, it has no vulnerabilities, it has a Permissive License and it has low support. You can download it from GitHub.

This is the example source code for my (in-progress) book, Practical Crypto with Go. You can read the book online.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              gocrypto has a low active ecosystem.
              It has 138 star(s) with 32 fork(s). There are 15 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 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 gocrypto is current.

            kandi-Quality Quality

              gocrypto has no bugs reported.

            kandi-Security Security

              gocrypto has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.

            kandi-License License

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

            kandi-Reuse Reuse

              gocrypto releases are not available. You will need to build from source code and install.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of gocrypto
            Get all kandi verified functions for this library.

            gocrypto Key Features

            No Key Features are available at this moment for gocrypto.

            gocrypto Examples and Code Snippets

            No Code Snippets are available at this moment for gocrypto.

            Community Discussions

            QUESTION

            How do you encrypt large files / byte streams in Go?
            Asked 2018-Oct-21 at 01:57

            I have some large files I would like to AES encrypt before sending over the wire or saving to disk. While it seems possible to encrypt streams, there seems to be warnings against doing this and instead people recommend splitting the files into chunks and using GCM or crypto/nacl/secretbox.

            Processing streams of data is more difficult due to the authenticity requirement. We can’t encrypt-then-MAC: by it’s nature, we usually don’t know the size of a stream. We can’t send the MAC after the stream is complete, as that usually is indicated by the stream being closed. We can’t decrypt a stream on the fly, because we have to see the entire ciphertext in order to check the MAC. Attempting to secure a stream adds enormous complexity to the problem, with no good answers. The solution is to break the stream into discrete chunks, and treat them as messages.

            Files are segmented into 4KiB blocks. Each block gets a fresh random 128 bit IV each time it is modified. A 128-bit authentication tag (GHASH) protects each block from modifications.

            If a large amount of data is decrypted it is not always possible to buffer all decrypted data until the authentication tag is verified. Splitting the data into small chunks fixes the problem of deferred authentication checks but introduces a new one. The chunks can be reordered... ...because every chunk is encrypted separately. Therefore the order of the chunks must be encoded somehow into the chunks itself to be able to detect rearranging any number of chunks.

            Can anyone with actual cryptography experience point me in the right direction?

            Update

            I realized after asking this question that there is a difference between simply not being able to fit the whole byte stream into memory (encrypting a 10GB file) and the byte stream also being an unknown length that could continue long past the need for the stream's start to be decoded (an 24-hour live video stream).

            I am mostly interested in large blobs where the end of the stream can be reached before the beginning needs to be decoded. In other words, encryption that does not require the whole plaintext/ciphertext to be loaded into memory at the same time.

            ...

            ANSWER

            Answered 2018-Mar-29 at 06:52

            As you've already discovered from your research, there isn't much of an elegant solution for authenticated encryption of large files.

            There are traditionally two ways to approach this problem:

            • Split the file into chunks, encrypt each chunk individually and let each chunk have its own authentication tag. AES-GCM would be the best mode to use for this. This method causes file size bloating proportionate to the size of the file. You'll also need a unique nonce for each chunk. You also need a way to indicate where chunks begin/end.

            • Encrypt using AES-CTR with a buffer, call Hash.Write on an HMAC for each buffer of encrypted data. The benefit of this is that encrypting can be done in one pass. The downside is that decryption requires one pass to validate the HMAC and then another pass to actually decrypt. The upside here is that the file size remains the same, plus roughly ~48 or so bytes for the IV and HMAC result.

            Neither is ideal, but for very large files (~2GB or more), the second option is probably preferred.

            I have included an example of encryption in Go using the second method below. In this scenario, the last 48 bytes are the IV (16 bytes) and the result of the HMAC (32 bytes). Note the HMACing of the IV also.

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

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

            Vulnerabilities

            No vulnerabilities reported

            Install gocrypto

            You can download it from GitHub.

            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/kisom/gocrypto.git

          • CLI

            gh repo clone kisom/gocrypto

          • sshUrl

            git@github.com:kisom/gocrypto.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

            Explore Related Topics

            Consider Popular Cryptography Libraries

            dogecoin

            by dogecoin

            tink

            by google

            crypto-js

            by brix

            Ciphey

            by Ciphey

            libsodium

            by jedisct1

            Try Top Libraries by kisom

            pypcapfile

            by kisomPython

            go-schannel

            by kisomGo

            aescrypt

            by kisomGo

            surfraw

            by kisomShell

            cryptutils

            by kisomGo