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 :

http://golang.org/pkg/crypto/des/#KeySizeError.Error

Advertisement