You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
package crypto
import (
"bytes"
"errors"
)
var ErrPKCS = errors . New ( "naza.crypto: fxxk" )
// @param blockSize 取值范围[0, 255]
// 如果是AES, 见标准库中aes.BlockSize等于16
func EncryptPKCS7 ( in [ ] byte , blockSize int ) [ ] byte {
paddingLength := blockSize - len ( in ) % blockSize
paddingBuf := bytes . Repeat ( [ ] byte { byte ( paddingLength ) } , paddingLength )
return append ( in , paddingBuf ... )
}
func DecryptPKCS7 ( in [ ] byte ) ( [ ] byte , error ) {
totalLength := len ( in )
if totalLength < 1 {
return nil , ErrPKCS
}
paddingLength := int ( in [ totalLength - 1 ] )
if totalLength < paddingLength {
return nil , ErrPKCS
}
return in [ : totalLength - int ( paddingLength ) ] , nil
}
func EncryptPKCS5 ( in [ ] byte ) [ ] byte {
return EncryptPKCS7 ( in , 8 )
}
func DecryptPKCS5 ( in [ ] byte ) ( [ ] byte , error ) {
return DecryptPKCS7 ( in )
}