當前位置: 首頁>>代碼示例>>Golang>>正文


Golang secure.NewAesGCM函數代碼示例

本文整理匯總了Golang中github.com/cloudfoundry/gorouter/common/secure.NewAesGCM函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewAesGCM函數的具體用法?Golang NewAesGCM怎麽用?Golang NewAesGCM使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewAesGCM函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: CreateCrypto

func CreateCrypto(c *cli.Context) (*secure.AesGCM, error) {
	keyPath := c.String("key-path")

	if keyPath == "" {
		usr, err := user.Current()
		if err != nil {
			fmt.Println(err.Error())
		}
		keyPath = usr.HomeDir + "/.rss/key"
	}

	key, err := ioutil.ReadFile(keyPath)
	if err != nil {
		fmt.Printf("Unable to read key file: %s\n%s\n", keyPath, err.Error())
		return nil, err
	}

	key = bytes.Trim(key, "\n")
	secretPbkdf := secure.NewPbkdf2(key, 16)
	crypto, err := secure.NewAesGCM(secretPbkdf)
	if err != nil {
		fmt.Printf("Error creating crypto: %s\n", err)
		return nil, err
	}
	return crypto, nil
}
開發者ID:idouba,項目名稱:gorouter,代碼行數:26,代碼來源:utils.go

示例2: CreateCrypto

func CreateCrypto(c *cli.Context) (*secure.AesGCM, error) {
	keyPath := c.String("key-path")

	if keyPath == "" {
		usr, err := user.Current()
		if err != nil {
			fmt.Println(err.Error())
		}
		keyPath = usr.HomeDir + "/.rss/key"
	}

	key, err := ioutil.ReadFile(keyPath)
	if err != nil {
		fmt.Printf("Unable to read key file: %s\n%s\n", keyPath, err.Error())
		return nil, err
	}

	secretDecoded, err := base64.StdEncoding.DecodeString(string(key))
	if err != nil {
		fmt.Printf("Error decoding key: %s\n", err)
		return nil, err
	}

	crypto, err := secure.NewAesGCM(secretDecoded)
	if err != nil {
		fmt.Printf("Error creating crypto: %s\n", err)
		return nil, err
	}
	return crypto, nil
}
開發者ID:jungle0755,項目名稱:gorouter,代碼行數:30,代碼來源:utils.go

示例3: createCrypto

func createCrypto(logger lager.Logger, secret string) *secure.AesGCM {
	// generate secure encryption key using key derivation function (pbkdf2)
	secretPbkdf2 := secure.NewPbkdf2([]byte(secret), 16)
	crypto, err := secure.NewAesGCM(secretPbkdf2)
	if err != nil {
		logger.Fatal("error-creating-route-service-crypto", err)
	}
	return crypto
}
開發者ID:rakutentech,項目名稱:gorouter,代碼行數:9,代碼來源:main.go

示例4: createCrypto

func createCrypto(logger *steno.Logger, secret string) *secure.AesGCM {
	// generate secure encryption key using key derivation function (pbkdf2)
	secretPbkdf2 := secure.NewPbkdf2([]byte(secret), 16)
	crypto, err := secure.NewAesGCM(secretPbkdf2)
	if err != nil {
		logger.Errorf("Error creating route service crypto: %s\n", err)
		os.Exit(1)
	}
	return crypto
}
開發者ID:idouba,項目名稱:gorouter,代碼行數:10,代碼來源:main.go

示例5: createCrypto

func createCrypto(secret string, logger *steno.Logger) *secure.AesGCM {
	secretDecoded, err := base64.StdEncoding.DecodeString(secret)
	if err != nil {
		logger.Errorf("Error decoding route service secret: %s\n", err)
		os.Exit(1)
	}

	crypto, err := secure.NewAesGCM(secretDecoded)
	if err != nil {
		logger.Errorf("Error creating route service crypto: %s\n", err)
		os.Exit(1)
	}
	return crypto
}
開發者ID:jungle0755,項目名稱:gorouter,代碼行數:14,代碼來源:main.go

示例6: TestProxy

	accessLogFile *test_util.FakeFile
	crypto        secure.Crypto
	logger        lager.Logger
	cryptoPrev    secure.Crypto
)

func TestProxy(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Proxy Suite")
}

var _ = BeforeEach(func() {
	logger = lagertest.NewTestLogger("test")
	var err error

	crypto, err = secure.NewAesGCM([]byte("ABCDEFGHIJKLMNOP"))
	Expect(err).NotTo(HaveOccurred())

	cryptoPrev = nil

	conf = config.DefaultConfig()
	conf.TraceKey = "my_trace_key"
	conf.EndpointTimeout = 500 * time.Millisecond
})

var _ = JustBeforeEach(func() {
	var err error
	mbus := fakeyagnats.Connect()
	r = registry.NewRouteRegistry(logger, conf, mbus, new(fakes.FakeRouteRegistryReporter))

	fakeEmitter := fake.NewFakeEventEmitter("fake")
開發者ID:sunatthegilddotcom,項目名稱:gorouter,代碼行數:31,代碼來源:proxy_suite_test.go

示例7:

		server := &http.Server{Handler: routeServiceHandler}
		go func() {
			err := server.Serve(tlsListener)
			Expect(err).ToNot(HaveOccurred())
		}()
	})

	BeforeEach(func() {
		conf.RouteServiceEnabled = true
		forwardedUrl = "http://my_host.com/resource+9-9_9?query=123&query$2=345#page1..5"

		routeServiceHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			metadataHeader := r.Header.Get(route_service.RouteServiceMetadata)
			signatureHeader := r.Header.Get(route_service.RouteServiceSignature)

			crypto, err := secure.NewAesGCM([]byte(cryptoKey))
			Expect(err).ToNot(HaveOccurred())
			_, err = route_service.SignatureFromHeaders(signatureHeader, metadataHeader, crypto)

			Expect(err).ToNot(HaveOccurred())
			Expect(r.Header.Get("X-CF-ApplicationID")).To(Equal(""))

			// validate client request header
			Expect(r.Header.Get("X-CF-Forwarded-Url")).To(Equal(forwardedUrl))

			w.Write([]byte("My Special Snowflake Route Service\n"))
		})

		crypto, err := secure.NewAesGCM([]byte(cryptoKey))
		Expect(err).ToNot(HaveOccurred())
開發者ID:idouba,項目名稱:gorouter,代碼行數:30,代碼來源:route_service_test.go

示例8:

	. "github.com/onsi/gomega"
)

var _ = Describe("Crypto", func() {

	var (
		aesGcm secure.Crypto
		key    []byte
	)

	BeforeEach(func() {
		var err error
		// valid key size
		key = []byte("super-secret-key")
		Expect(err).ToNot(HaveOccurred())
		aesGcm, err = secure.NewAesGCM(key)
		Expect(err).ToNot(HaveOccurred())
	})

	Describe("NewPbkdf2", func() {

		Context("when a plaintext secret is provided", func() {

			Context("when password length is less than desired key len", func() {
				It("generates an encryption key of desired ken length", func() {
					k := secure.NewPbkdf2([]byte(""), 16)
					Expect(k).To(HaveLen(16))

					k = secure.NewPbkdf2([]byte("short-key"), 16)
					Expect(k).To(HaveLen(16))
開發者ID:idouba,項目名稱:gorouter,代碼行數:30,代碼來源:crypto_test.go


注:本文中的github.com/cloudfoundry/gorouter/common/secure.NewAesGCM函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。