Golang crypto/des.NewCipher() function example

package crypto/des

NewCipher creates and returns a new cipher.Block.

Golang crypto/des.NewCipher() function usage example

 package main

  import (
 "fmt"
 "crypto/des"
  )

  func main() {

 key := "12345678" // 8 bytes! this is the DES block size in bytes

 block,err := des.NewCipher([]byte(key))

 if err != nil {
 fmt.Println(err)
 }

 fmt.Printf("%d bytes NewCipher key with block size of %d bytes\n", len(key), block.BlockSize)
  }

Output :

8 bytes NewCipher key with block size of 8752 bytes

Note : The key size must be exactly 8 bytes.

Reference :

http://golang.org/pkg/crypto/des/#NewCipher

Advertisement