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
+8.2k Golang : HttpRouter multiplexer routing example
+29.5k Golang : Login(Authenticate) with Facebook example
+9.6k Javascript : Read/parse JSON data from HTTP response
+13.1k Golang : How to get a user home directory path?
+19.4k Golang : Fix cannot download, $GOPATH not set error
+6.7k Golang : Humanize and Titleize functions
+5.2k JavaScript/JQuery : Redirect page examples
+10.2k Golang : How to profile or log time spend on execution?
+18.9k Golang : Read input from console line
+13.2k Golang : How to calculate the distance between two coordinates using Haversine formula
+13.7k Golang : Check if an integer is negative or positive
+5.2k Golang : Print instead of building pyramids