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
+5.6k PHP : Fix Call to undefined function curl_init() error
+14.6k Golang : How to get URL port?
+6.2k PHP : Get client IP address
+26.9k Golang : Force your program to run with root permissions
+5.6k Unix/Linux : How to find out the hard disk size?
+4.6k Linux : sudo yum updates not working
+4.7k Chrome : How to block socketloop.com links in Google SERP?
+12.8k Golang : Convert int(year) to time.Time type
+5.5k Golang : Stop goroutine without channel
+18.4k Golang : Logging with logrus
+5.7k Unix/Linux/MacOSx : Get local IP address
+6k Fontello : How to load and use fonts?