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
+9.1k Golang : Serving HTTP and Websocket from different ports in a program example
+11k How to test Facebook App on localhost ?
+9.6k Golang : Read file with ioutil
+7.1k Golang : Gorrila mux.Vars() function example
+6.1k Golang : Missing Subversion command
+5.9k Golang : Generate multiplication table from an integer example
+7.3k Golang : How to convert strange string to JSON with json.MarshalIndent
+12.1k Golang : Sort and reverse sort a slice of runes
+11.3k Golang : Characters limiter example
+11.1k Golang : Roll the dice example
+12.3k Golang : Display list of countries and ISO codes
+46.4k Golang : Encode image to base64 example