1 回答
TA贡献1893条经验 获得超10个赞
散列函数必须由import _ "whatever". 不会自动链接到您的二进制文件中。实际上,没有明确(或可传递地)导入的内容。但是,如果您直接使用一些非导入的实体,编译器/链接器会抱怨。散列函数 OTOH 以及 stdlib 的其他一些部分通过散列接口使用一种后期绑定。
(09:25) jnml@fsc-r550:~/src/tmp/SO/17986762$ cat main.go
package main
import (
"fmt"
"log"
"os"
"code.google.com/p/go.crypto/openpgp"
"code.google.com/p/go.crypto/openpgp/armor"
_ "code.google.com/p/go.crypto/ripemd160"
)
func main() {
to, err := openpgp.NewEntity("John Smith", "comment", "john@example.com", nil)
if err != nil {
log.Fatal(err)
}
from, err := openpgp.NewEntity("John Smith", "comment", "john@example.com", nil)
if err != nil {
log.Fatal(err)
}
recipients := []*openpgp.Entity{to}
armorer, err := armor.Encode(os.Stdout, "PGP MESSAGE", nil)
if err != nil {
log.Fatal(err)
}
defer armorer.Close()
encrypter, err := openpgp.Encrypt(armorer, recipients, from, nil, nil)
if err != nil {
log.Fatal(err)
}
defer encrypter.Close()
fmt.Fprintf(encrypter, "Hello! How are you?")
}
(09:25) jnml@fsc-r550:~/src/tmp/SO/17986762$ go run main.go
-----BEGIN PGP MESSAGE-----
wcBMA6art6sLA/RNAQgAyScgc5RZErJ59rFreeOiotvMcSDgIRgdoxyKjo7qHxhz
jwhxYv/fqLgpYq5AbOCXVUK4Ubt+vmr+ET/txhW5tCx96cTZXVmyuke89+yQ6SQ7
ESlZxq9X973lpOq/I1rXY6T8bgfz4TY3w9Ur0XevnB9uJKv7nMaWCG46f//uT1P8
wD7eqv8hupJK+FnyzU5SzDyeO20ZzyN0e6M2GobhmmOmik3iB491+NskC5gBL2oB
kZBJROOrBtp9z27YXZTFjewgxzkUNzw+IVlsQD5h6XiyzOIfD2UtxvzxJs6qe3Kf
iAlqPfsETCBi6qxpnaBlUVQycfMCClbWzoI54dq3m9LgAeOJhljWnwSGnOGdLOGW
G+MDigPW5TYnD+JX4dRg4G3g/+Dm4VyV4DbihPWbZ+CA5IOlWefWOHpkJSOQi6JU
H1DgluHA9eAb4FjgYuGBaeCz5N8ur0undv+IiD08IJXlzgjiP74GiuGc2uFFgeFz
YOH3K+jHj0qPYhceyDp8mtmCgy7E/523HYsLgzu9nXbKajafo/6HRa2KLM1d0VGM
qZsEqF6Kr/1m1qBaV94oWju5z0f+bBtNCgXjbP2ibFAUlmuFvKsRHZVsdOo8BLkd
ed5Q9sw1fMXSzA6cxYClpeN6BmJ3KlLEkn6wxmbpUxR6VI17I2iZNA4rhzU2fYRR
egESqUF2tfZP5MDNUx8QzQdP6ch3okdKBg7hga59YA66QqbV2KczixWaFssWyqI+
AtInYYD/bHJQYHGdHgST3aLUO6wEALgpcK55AWHHjJAwoZUoVkEFN8KN6pAEutur
jRjTcfnkbCz4l/CxuN+jzLTevogM5NO+RU7ZKMkKVhzRoGM95lviTSwkj+E5mgA=
=wWmw
-----END PGP MESSAGE-----(09:26) jnml@fsc-r550:~/src/tmp/SO/17986762$
- 1 回答
- 0 关注
- 366 浏览
添加回答
举报