rijndael256

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const BlockSize = 32

Variables

View Source
var ErrInvalidKeySize = errors.New("key size must be 16, 24 or 32 bytes")

Functions

func NewCipher

func NewCipher(key []byte) (cipher.Block, error)

Types

type Cipher

type Cipher struct {
	// contains filtered or unexported fields
}

func (*Cipher) BlockSize

func (c *Cipher) BlockSize() int

func (*Cipher) Decrypt

func (c *Cipher) Decrypt(dst, src []byte)
Example
package main

import (
	"bytes"
	"fmt"

	"github.com/elvishp2006/go-mcrypt/pkg/rijndael256"
)

func main() {
	r, err := rijndael256.NewCipher([]byte("1234567890123456"))

	if err != nil {
		panic(err)
	}

	encrypted := make([]byte, 32)

	r.Encrypt(encrypted, []byte("123"))

	decrypted := make([]byte, 32)

	r.Decrypt(decrypted, encrypted)

	fmt.Println(string(bytes.Trim(decrypted, "\x00")))

}
Output:

123

func (*Cipher) Encrypt

func (c *Cipher) Encrypt(dst, src []byte)
Example
package main

import (
	"encoding/base64"
	"fmt"

	"github.com/elvishp2006/go-mcrypt/pkg/rijndael256"
)

func main() {
	r, err := rijndael256.NewCipher([]byte("1234567890123456"))

	if err != nil {
		panic(err)
	}

	encrypted := make([]byte, 32)

	r.Encrypt(encrypted, []byte("123"))

	fmt.Println(base64.StdEncoding.EncodeToString(encrypted))

}
Output:

Pd0dwZIwEvgxedRZNxBopvDWg1xbLrAwoh7RA/i1MW0=

Jump to

Keyboard shortcuts

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