crypto

package
v0.0.0-...-8c35ede Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 6, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

README

example

package main

import (
	"encoding/hex"
	"fmt"

	"github.com/go-bai/glib/crypto"
)

func main() {
	plaintext := []byte("hello world")
	key := []byte("1234567812345678")
	ciphertext, err := crypto.AESCBCEncrypt(plaintext, key)
	if err != nil {
		panic(err)
	}
	ciphertextHex := hex.EncodeToString(ciphertext)
	fmt.Printf("ciphertextHex: %s\n", ciphertextHex)

	p, err := crypto.AESCBCDecrypt(ciphertext, key)
	if err != nil {
		panic(err)
	}
	fmt.Printf("plaintext: \"%s\"\n", string(p))
}

reference

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AESCBCDecrypt

func AESCBCDecrypt(ciphertext, key []byte) (plaintext []byte, err error)

func AESCBCEncrypt

func AESCBCEncrypt(plainText, key []byte) (ciphertext []byte, err error)

AES + CBC(Cipher Block Chaining) + PKCS7Padding echo -n 'plainText' | openssl aes-128-cbc -e -K 'hex(key)' -iv 'hex(iv)' -nosalt | hexdump -e '16/1 "%02x"'

func PKCS7Padding

func PKCS7Padding(data []byte, blockSize int) []byte

https://datatracker.ietf.org/doc/html/rfc2315#section-10.3 pad the data at the trailing end with blockSize - (len(data) mod blockSize) octets all having value blockSize - (len(data) mod blockSize). 1 < blockSize < 256

func PKCS7UnPadding

func PKCS7UnPadding(data []byte) []byte

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL