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
+6.2k PHP : Get client IP address
+16.4k Golang : How to implement two-factor authentication?
+51.9k Golang : How to get time in milliseconds?
+43.3k Golang : Convert []byte to image
+6.1k Golang : Scan forex opportunities by Bollinger bands
+7.1k Restart Apache or Nginx web server without password prompt
+6.6k Golang : Embedded or data bundling example
+6.3k Apt-get to install and uninstall Golang
+28k Golang : Move file to another directory
+5.8k Javascript : How to replace HTML inside <div>?
+23.7k Find and replace a character in a string in Go
+46.5k Golang : Marshal and unmarshal json.RawMessage struct example