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


Golang elliptic.P224函數代碼示例

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


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

示例1: TestKeyLength

func TestKeyLength(t *testing.T) {
	expNil := 0
	recNil := KeyLength(nil)
	if expNil != recNil {
		t.Fatal("KeyLength on nil did not return 0")
	}

	expNonsense := 0
	inNonsense := "string?"
	outNonsense := KeyLength(inNonsense)
	if expNonsense != outNonsense {
		t.Fatal("KeyLength malfunctioning on nonsense input")
	}

	//test the ecdsa branch
	ecdsaPriv, _ := ecdsa.GenerateKey(elliptic.P224(), rand.Reader)
	ecdsaIn, _ := ecdsaPriv.Public().(*ecdsa.PublicKey)
	expEcdsa := ecdsaIn.Curve.Params().BitSize
	outEcdsa := KeyLength(ecdsaIn)
	if expEcdsa != outEcdsa {
		t.Fatal("KeyLength malfunctioning on ecdsa input")
	}

	//test the rsa branch
	rsaPriv, _ := rsa.GenerateKey(rand.Reader, 256)
	rsaIn, _ := rsaPriv.Public().(*rsa.PublicKey)
	expRsa := rsaIn.N.BitLen()
	outRsa := KeyLength(rsaIn)

	if expRsa != outRsa {
		t.Fatal("KeyLength malfunctioning on rsa input")
	}
}
開發者ID:codyli520,項目名稱:cfssl,代碼行數:33,代碼來源:helpers_test.go

示例2: TestRoundTripPkcs8Ecdsa

func TestRoundTripPkcs8Ecdsa(t *testing.T) {
	privateKey, err := ecdsa.GenerateKey(elliptic.P224(), rand.Reader)
	if err != nil {
		t.Fatalf("failed to generate a private key: %s", err)
	}

	bytes, err := marshalPKCS8PrivateKey(privateKey)
	if err != nil {
		t.Fatalf("failed to marshal private key: %s", err)
	}

	key, err := x509.ParsePKCS8PrivateKey(bytes)
	if err != nil {
		t.Fatalf("failed to parse private key: %s", err)
	}

	actualPrivateKey, ok := key.(*ecdsa.PrivateKey)
	if !ok {
		t.Fatalf("expected key to be of type *ecdsa.PrivateKey, but actual was %T", key)
	}

	// sanity check, not exhaustive
	if actualPrivateKey.D.Cmp(privateKey.D) != 0 {
		t.Errorf("private key's D did not round trip")
	}
	if actualPrivateKey.X.Cmp(privateKey.X) != 0 {
		t.Errorf("private key's X did not round trip")
	}
	if actualPrivateKey.Y.Cmp(privateKey.Y) != 0 {
		t.Errorf("private key's Y did not round trip")
	}
	if actualPrivateKey.Curve.Params().B.Cmp(privateKey.Curve.Params().B) != 0 {
		t.Errorf("private key's Curve.B did not round trip")
	}
}
開發者ID:boumenot,項目名稱:packer,代碼行數:35,代碼來源:pkcs8_test.go

示例3: TestKeyGeneration

func TestKeyGeneration(t *testing.T) {
	testKeyGeneration(t, elliptic.P224(), "p224")
	if testing.Short() {
		return
	}
	testKeyGeneration(t, gost3410a, "gost3410a")
}
開發者ID:zeil,項目名稱:gostcrypto,代碼行數:7,代碼來源:gost3410_test.go

示例4: createCertificateAndKeys

func createCertificateAndKeys() {

	// http://golang.org/pkg/crypto/x509/#Certificate

	privatekey, err := ecdsa.GenerateKey(elliptic.P224(), rand.Reader)
	if err != nil {
		fmt.Println(err)
	}
	publickey := &privatekey.PublicKey

	certTemplate := getCertificateTemplate()
	cert, err := x509.CreateCertificate(rand.Reader, certTemplate, certTemplate, publickey, privatekey)

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

	writePemCertificate(cert, "btcd/root/.btcd/rpc.cert")
	writePemPrivateKey(privatekey, "btcd/root/.btcd/rpc.key")

	writePemCertificate(cert, "btcwallet/root/.btcd/rpc.cert")
	writePemCertificate(cert, "btcwallet/root/.btcwallet/btcd.cert")
	writePemCertificate(cert, "btcwallet/root/.btcwallet/rpcw.cert")
	writePemPrivateKey(privatekey, "btcwallet/root/.btcwallet/rpcw.key")
}
開發者ID:wid,項目名稱:btcd-in-a-box,代碼行數:25,代碼來源:initrpc.go

示例5: GenerateKeyPair

// GenerateKeyPair generates a private/public key pair,
// keys are returned as hex-encoded strings
func GenerateKeyPair() (private_key_hex, public_key_hex string) {
	// generate keys
	private_key, err := ecdsa.GenerateKey(elliptic.P224(), rand.Reader)
	if err != nil {
		panic(err)
	}

	// marshal private key
	private_key_bytes, err := x509.MarshalECPrivateKey(private_key)
	if err != nil {
		panic(err)
	}

	// marshal public key
	public_key_bytes, err := x509.MarshalPKIXPublicKey(&private_key.PublicKey)
	if err != nil {
		panic(err)
	}

	// hex encode and return result
	private_key_hex = hex.EncodeToString(private_key_bytes)
	public_key_hex = hex.EncodeToString(public_key_bytes)

	return private_key_hex, public_key_hex
}
開發者ID:vgorin,項目名稱:cryptogo,代碼行數:27,代碼來源:ecdsa.go

示例6: main

func main() {
	u := must(url.Parse("http://SUCCESS"))
	b, x, y := must(elliptic.GenerateKey(elliptic.P224(), ConstWriter(0)))
	if must(url.Parse("http://example.com/a/b")).IsAbs() {
		fmt.Println(u.Host)
	}
}
開發者ID:elazarl,項目名稱:gosloppy,代碼行數:7,代碼來源:a.go

示例7: TestECDSAVerifierOtherCurves

func TestECDSAVerifierOtherCurves(t *testing.T) {
	curves := []elliptic.Curve{elliptic.P224(), elliptic.P256(), elliptic.P384(), elliptic.P521()}

	for _, curve := range curves {
		ecdsaPrivKey, err := ecdsa.GenerateKey(curve, rand.Reader)

		// Get a DER-encoded representation of the PublicKey
		ecdsaPubBytes, err := x509.MarshalPKIXPublicKey(&ecdsaPrivKey.PublicKey)
		assert.NoError(t, err, "failed to marshal public key")

		// Get a DER-encoded representation of the PrivateKey
		ecdsaPrivKeyBytes, err := x509.MarshalECPrivateKey(ecdsaPrivKey)
		assert.NoError(t, err, "failed to marshal private key")

		testECDSAKey := data.NewPrivateKey(data.ECDSAKey, ecdsaPubBytes, ecdsaPrivKeyBytes)

		// Sign some data using ECDSA
		message := []byte("test data for signing")
		hashed := sha256.Sum256(message)
		signedData, err := ecdsaSign(testECDSAKey, hashed[:])
		assert.NoError(t, err)

		// Create and call Verify on the verifier
		ecdsaVerifier := ECDSAVerifier{}
		err = ecdsaVerifier.Verify(testECDSAKey, signedData, message)
		assert.NoError(t, err, "expecting success but got error while verifying data using ECDSA")

		// Make sure an invalid signature fails verification
		signedData[0]++
		err = ecdsaVerifier.Verify(testECDSAKey, signedData, message)
		assert.Error(t, err, "expecting error but got success while verifying data using ECDSA")
	}
}
開發者ID:programmerq,項目名稱:notary,代碼行數:33,代碼來源:verifiers_test.go

示例8: TestNullParametersPkcs8Ecdsa

func TestNullParametersPkcs8Ecdsa(t *testing.T) {
	privateKey, err := ecdsa.GenerateKey(elliptic.P224(), rand.Reader)
	if err != nil {
		t.Fatalf("failed to generate a private key: %s", err)
	}

	checkNullParameter(t, privateKey)
}
開發者ID:boumenot,項目名稱:packer,代碼行數:8,代碼來源:pkcs8_test.go

示例9: BenchmarkRawCreateP224

func BenchmarkRawCreateP224(b *testing.B) {
	data := "foo"
	k, _ := ecdsa.GenerateKey(elliptic.P224(), rand.Reader)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		ecdsa.Sign(rand.Reader, k, []byte(data))
	}
}
開發者ID:sdgoij,項目名稱:TheDistributedBay,代碼行數:8,代碼來源:crypto_test.go

示例10: TestSignAndVerify

func TestSignAndVerify(t *testing.T) {
	testSignAndVerify(t, elliptic.P224(), "p224")
	if testing.Short() {
		return
	}
	testSignAndVerify(t, elliptic.P256(), "p256")
	testSignAndVerify(t, elliptic.P384(), "p384")
	testSignAndVerify(t, elliptic.P521(), "p521")
}
開發者ID:h8liu,項目名稱:golang,代碼行數:9,代碼來源:ecdsa_test.go

示例11: TestKeyGeneration

func TestKeyGeneration(t *testing.T) {
	testKeyGeneration(t, elliptic.P224(), "p224")
	if testing.Short() {
		return
	}
	testKeyGeneration(t, elliptic.P256(), "p256")
	testKeyGeneration(t, elliptic.P384(), "p384")
	testKeyGeneration(t, elliptic.P521(), "p521")
}
開發者ID:h8liu,項目名稱:golang,代碼行數:9,代碼來源:ecdsa_test.go

示例12: TestINDCCA

func TestINDCCA(t *testing.T) {
	testINDCCA(t, elliptic.P224(), "p224")
	if testing.Short() {
		return
	}
	testINDCCA(t, elliptic.P256(), "p256")
	testINDCCA(t, elliptic.P384(), "p384")
	testINDCCA(t, elliptic.P521(), "p521")
}
開發者ID:sreis,項目名稱:go,代碼行數:9,代碼來源:ecdsa_test.go

示例13: TestNewSignatureVerifierFailsWithBadKeyParametersForEC

func TestNewSignatureVerifierFailsWithBadKeyParametersForEC(t *testing.T) {
	k, err := ecdsa.GenerateKey(elliptic.P224(), rand.Reader)
	if err != nil {
		t.Fatalf("Failed to generate ECDSA key on P224: %v", err)
	}
	if _, err := NewSignatureVerifier(k); err == nil {
		t.Fatal("Incorrectly created new SignatureVerifier with EC P224 key.")
	}
}
開發者ID:Cyber-Forensic,項目名稱:certificate-transparency,代碼行數:9,代碼來源:signatures_test.go

示例14: TestWillAllowNonCompliantECKeyWithOverride

func TestWillAllowNonCompliantECKeyWithOverride(t *testing.T) {
	*allowVerificationWithNonCompliantKeys = true
	k, err := ecdsa.GenerateKey(elliptic.P224(), rand.Reader)
	if err != nil {
		t.Fatalf("Failed to generate EC key on P224: %v", err)
	}
	if _, err := NewSignatureVerifier(k.Public()); err != nil {
		t.Fatalf("Incorrectly disallowed P224 EC key with override set: %v", err)
	}
}
開發者ID:Cyber-Forensic,項目名稱:certificate-transparency,代碼行數:10,代碼來源:signatures_test.go

示例15: BenchmarkRawVerifyP224

func BenchmarkRawVerifyP224(b *testing.B) {
	data := "foo"
	k, _ := ecdsa.GenerateKey(elliptic.P224(), rand.Reader)
	R, S, _ := ecdsa.Sign(rand.Reader, k, []byte(data))
	pk := &k.PublicKey
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		ecdsa.Verify(pk, []byte(data), R, S)
	}
}
開發者ID:sdgoij,項目名稱:TheDistributedBay,代碼行數:10,代碼來源:crypto_test.go


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