예제 #1
0
파일: keys.go 프로젝트: robmurtha/goq
func loadCrypter(optCrypter string) dkeyczar.Crypter {
	if optCrypter == "" {
		return nil
	}

	//fmt.Println("using crypter:", optCrypter)
	r := dkeyczar.NewFileReader(optCrypter)
	crypter, err := dkeyczar.NewCrypter(r)
	if err != nil {
		panic(fmt.Sprintf("failed to load crypter: %s", err))
		//return nil
	}
	return crypter
}
예제 #2
0
파일: keys.go 프로젝트: robmurtha/goq
func (k *CypherKey) InstantiateCrypter() {
	c := loadCrypter("")
	r := loadReader(k.Loc, c)
	if r == nil {
		panic(fmt.Sprintf("could not read keys from '%s'", k.Loc))
	}

	// a crypter can decode as well as encode
	crypter, err := dkeyczar.NewCrypter(r)
	if err != nil {
		panic(err)
	}
	crypter.SetEncoding(dkeyczar.NO_ENCODING)
	//crypter.SetEncoding(dkeyczar.BASE64W)
	k.crypter = crypter
}
예제 #3
0
func writeDecryptTest(dir string) {

	fulldir := TESTDATA + dir

	r := dkeyczar.NewFileReader(fulldir)
	crypter, _ := dkeyczar.NewCrypter(r)

	ciphertext, _ := crypter.Encrypt([]byte(PLAINTEXT))
	fmt.Println(`
check_decrypt(readers.FileReader("` + fulldir + `"),
    "` + dir + `",
    "` + PLAINTEXT + `",
    "` + ciphertext + `",
)
`)

}
예제 #4
0
func writeKeyczartTest(dir string) {

	fulldir := TESTDATA + dir

	km := dkeyczar.NewKeyManager()

	r := dkeyczar.NewFileReader(fulldir)

	km.Load(r)

	json := km.ToJSONs(nil)

	fmt.Println(`

meta = """` + json[0] + `"""
keys={`)

	for i := 1; i < len(json); i++ {
		fmt.Println("    " + strconv.Itoa(i) + `: """` + json[i] + `""",`)
	}
	fmt.Println(`}
r = JSONReader(meta, keys)`)
	signer, _ := dkeyczar.NewSigner(r)
	if signer != nil {

		signature, _ := signer.Sign([]byte(PLAINTEXT))

		fmt.Println(
			`check_verify(r,
        "json ` + dir + `",
        "` + PLAINTEXT + `",
        "` + signature + `",
)`)
	} else {
		crypter, _ := dkeyczar.NewCrypter(r)

		ciphertext, _ := crypter.Encrypt([]byte(PLAINTEXT))
		fmt.Println(
			`check_decrypt(r,
    "json ` + dir + `",
    "` + PLAINTEXT + `",
    "` + ciphertext + `",
)`)
	}

}