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
+8k Golang : Handle Palindrome string with case sensitivity and unicode
+6.9k Mac OSX : Find large files by size
+5.7k Golang : Struct field tags and what is their purpose?
+37.5k Golang : Converting a negative number to positive number
+13.2k Golang : Skip blank/empty lines in CSV file and trim whitespaces example
+6.9k Golang : Fibonacci number generator examples
+6.5k Unix/Linux : How to get own IP address ?
+18.6k Golang : Find IP address from string
+13.7k Golang : Image to ASCII art example
+16.6k Golang : Generate QR codes for Google Authenticator App and fix "Cannot interpret QR code" error
+7.9k Javascript : Put image into Chrome browser's console
+22.4k Golang : How to read JPG(JPEG), GIF and PNG files ?