Golang crypto/des.KeySizeError() function example
package crypto/des
Golang crypto.des.KeySizeError() function usage example
package main
import (
"fmt"
"crypto/des"
)
func main() {
key := "2345678" // not 8 bytes! this is cause KeySizeError
block,err := des.NewCipher([]byte(key))
if err != nil {
fmt.Printf("%s \n", err.Error()) // / KeySizeError function will return error message
}
fmt.Printf("%d bytes NewCipher key with block size of %d bytes\n", len(key), block.BlockSize)
}
Output :
crypto/des: invalid key size 7
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x225c]
Reference :
Advertisement
Something interesting
Tutorials
+16.8k Golang : Get own process identifier
+8.2k Golang : Routes multiplexer routing example with regular expression control
+10.2k Golang : Bcrypting password
+9.7k PHP : Get coordinates latitude/longitude from string
+62.7k Golang : Convert HTTP Response body to string
+29.7k Golang : Record voice(audio) from microphone to .WAV file
+8.9k Golang : What is the default port number for connecting to MySQL/MariaDB database ?
+27.5k Golang : Convert integer to binary, octal, hexadecimal and back to integer
+13.2k Golang : How to calculate the distance between two coordinates using Haversine formula
+4.7k Javascript : Access JSON data example
+23.5k Golang : Read a file into an array or slice example
+20.2k Golang : Reset or rewind io.Reader or io.Writer