padding

package
v1.0.45 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

This package implements PKCS#7 padding to byte slices. Padding works by calculating the amount of needed padding and repeating that number to fill in the rest of the slice up to the block size. This way, in order to unpad the slice, you check the value held in the last slot and then remove that many bytes from the end.

By defniition, PKCS#7 only padds for block sizes between 1 and 255 inclusive. If the supplied byte slice is a multiple of the block size, N, an extra N amount of bytes is appended all of value N.

Please review the tests for this package for examples.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pkcs5Padding added in v1.0.25

func Pkcs5Padding(ciphertext []byte, blockSize int) []byte

func Pkcs5Unpadding added in v1.0.25

func Pkcs5Unpadding(origData []byte) (dst []byte, err error)

func Pkcs7Padding added in v1.0.24

func Pkcs7Padding(src []byte, blockSize int) []byte

Pad takes a source byte slice and a block size. It will determine the needed amount of padding, n, and appends byte(n) to the source n times.

Example Input: Block Size 8, Source {0xDE, 0xAD, 0xBE, 0xEF}

Expected Output: {0xDE, 0xAD, 0xBE, 0xEF, 0x04, 0x04, 0x04, 0x04}

func Pkcs7Unpadding added in v1.0.24

func Pkcs7Unpadding(src []byte) (dst []byte, err error)

Unpad takes a source byte slice and will remove any padding added according to PKCS#7 specifications. An error is returned for invalid padding.

Types

This section is empty.

Jump to

Keyboard shortcuts

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