{"id":29288652,"url":"https://github.com/regnull/easyecc","last_synced_at":"2025-07-06T03:08:27.044Z","repository":{"id":51078764,"uuid":"370051929","full_name":"regnull/easyecc","owner":"regnull","description":"Easy Elliptic Curve Cryptography on multiple curves, written in Go.","archived":false,"fork":false,"pushed_at":"2023-10-19T11:38:52.000Z","size":161,"stargazers_count":13,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-21T03:34:30.364Z","etag":null,"topics":["bitcoin","cryptography","ethereum","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/regnull.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-23T12:50:35.000Z","updated_at":"2024-05-08T10:03:17.000Z","dependencies_parsed_at":"2024-06-21T02:36:48.063Z","dependency_job_id":null,"html_url":"https://github.com/regnull/easyecc","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/regnull/easyecc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/regnull%2Feasyecc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/regnull%2Feasyecc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/regnull%2Feasyecc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/regnull%2Feasyecc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/regnull","download_url":"https://codeload.github.com/regnull/easyecc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/regnull%2Feasyecc/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263841682,"owners_count":23518490,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bitcoin","cryptography","ethereum","golang"],"created_at":"2025-07-06T03:08:26.458Z","updated_at":"2025-07-06T03:08:27.035Z","avatar_url":"https://github.com/regnull.png","language":"Go","readme":"# Easy Elliptic Curve Cryptography in Go\n\n![GitHub Workflow Status](https://github.com/regnull/easyecc/actions/workflows/go.yml/badge.svg)\n[![GoDoc reference example](https://img.shields.io/badge/godoc-reference-blue.svg)](https://godoc.org/github.com/regnull/easyecc)\n[![GoReportCard example](https://goreportcard.com/badge/github.com/regnull/easyecc)](https://goreportcard.com/report/github.com/regnull/easyecc)\n[![Coverage Status](https://coveralls.io/repos/github/regnull/easyecc/badge.svg?branch=master)](https://coveralls.io/github/regnull/easyecc?branch=master)\n\nThis package ties several other commonly used cryptography packages together. The goal is to make common cryptographic operations simple. \nThe following elliptic curves are supported:\n\n* [secp256k1](https://en.bitcoin.it/wiki/Secp256k1)\n\n* [P-256](https://neuromancer.sk/std/nist/P-256)\n\n* [P-384](https://neuromancer.sk/std/nist/P-384)\n\n* [P-521](https://neuromancer.sk/std/nist/P-521)\n\n\nThis package was originally the part of https://github.com/regnull/ubikom, but then became its own little package, because why not.\n\n## Examples\n\n(see examples_test.go and encryption_test.go files).\n\nElliptic curves are defined as constants:\n\n```Go\nconst (\n\tSECP256K1 EllipticCurve = 1\n\tP256      EllipticCurve = 2\n\tP384      EllipticCurve = 3\n\tP521      EllipticCurve = 4\n)\n```\n\nUse them when creating keys.\n\n## Sign hash and verify signature (Using [ECDSA](https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm))\n\n```Go\nprivateKey := CreatePrivateKey(P256, big.NewInt(12345))\ndata := \"super secret message\"\nhash := Hash256([]byte(data))\nsignature, err := privateKey.Sign(hash)\nif err != nil {\n\tlog.Fatal(err)\n}\npublicKey := privateKey.PublicKey()\nsuccess := signature.Verify(publicKey, hash)\nfmt.Printf(\"Signature verified: %v\\n\", success)\n// Output: Signature verified: true\n```\n\n## Encrypt with shared secret (Using [ECDH](https://en.wikipedia.org/wiki/Elliptic-curve_Diffie%E2%80%93Hellman)):\n\n```Go\naliceKey, err := GeneratePrivateKey(P256)\nif err != nil {\n\tlog.Fatal(err)\n}\nbobKey, err := GeneratePrivateKey(P256)\nif err != nil {\n\tlog.Fatal(err)\n}\ndata := \"super secret message\"\nencrypted, err := aliceKey.EncryptECDH([]byte(data), bobKey.PublicKey())\nif err != nil {\n\tlog.Fatal(err)\n}\ndecrypted, err := bobKey.DecryptECDH(encrypted, aliceKey.PublicKey())\nif err != nil {\n\tlog.Fatal(err)\n}\nfmt.Printf(\"%s\\n\", string(decrypted))\n// Output: super secret message\n```\n\n## Encrypt private key with passphrase\n\n```Go\nprivateKey := CreatePrivateKey(P256, big.NewInt(12345))\nencryptedKey, err := privateKey.EncryptKeyWithPassphrase(\"my passphrase\")\nif err != nil {\n\tlog.Fatal(err)\n}\ndecryptedKey, err := CreatePrivateKeyFromEncrypted(P256, encryptedKey, \"my passphrase\")\nfmt.Printf(\"%d\\n\", decryptedKey.Secret())\n// Output: 12345\n```\n\n## Serialize Public Key\n\n```Go\nprivateKey := CreatePrivateKey(P256, big.NewInt(12345))\npublicKey := privateKey.PublicKey()\nserializedCompressed := publicKey.SerializeCompressed()\nfmt.Printf(\"%x\\n\", serializedCompressed)\npublicKeyCopy, err := DeserializeCompressed(P256, serializedCompressed)\nif err != nil {\n\tlog.Fatal(err)\n}\nsameKey := publicKey.Equal(publicKeyCopy)\nfmt.Printf(\"the correct key was created: %v\\n\", sameKey)\n// Output: 0226efcebd0ee9e34a669187e18b3a9122b2f733945b649cc9f9f921e9f9dad812\n// the correct key was created: true\n```\n\n## Getting Bitcoin and Ethereum addresses:\n```Go\n// BitcoinAddress and EthereumAddress only work for secp256k1 curve.\nprivateKey := CreatePrivateKey(SECP256K1, big.NewInt(12345))\npublicKey := privateKey.PublicKey()\nbitcoinAddress, err := publicKey.BitcoinAddress()\nif err != nil {\n\tlog.Fatal(err)\n}\nfmt.Printf(\"Bitcoin address: %s\\n\", bitcoinAddress)\nethereumAddress, err := publicKey.EthereumAddress()\nif err != nil {\n\tlog.Fatal(err)\n}\nfmt.Printf(\"Ethereum address: %s\\n\", ethereumAddress)\n// Output: Bitcoin address: 12vieiAHxBe4qCUrwvfb2kRkDuc8kQ2VZ2\n// Ethereum address: 0xEB4665750b1382DF4AeBF49E04B429AAAc4d9929\n```\n\n## JWK Support\n\nEasyECC offers some limited JWK support (see https://www.rfc-editor.org/rfc/rfc7517).\nPrivate keys can be exported and imported as JWK JSON:\n```Go\nprivateKey := CreatePrivateKey(P256, big.NewInt(12345))\njwkBytes, err := privateKey.MarshalToJWK()\nif err != nil {\n\tlog.Fatal(err)\n}\nfmt.Printf(\"%s\\n\", jwkBytes)\n\nprivateKeyCopy, err := CreatePrivateKeyFromJWK(jwkBytes)\nif err != nil {\n\tlog.Fatal(err)\n}\nif privateKey.Equal(privateKeyCopy) {\n\tfmt.Printf(\"keys match!\")\n}\n// Output: {\n//   \"kty\": \"EC\",\n//   \"crv\": \"P-256\",\n//   \"x\": \"Ju/OvQ7p40pmkYfhizqRIrL3M5RbZJzJ+fkh6fna2BI\",\n//   \"y\": \"kCOL3pzHuzMNFQxncE3SWucFUgV0S28xv0BwdFhy0OY\",\n//   \"d\": \"MDk\"\n// }\n// keys match!\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fregnull%2Feasyecc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fregnull%2Feasyecc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fregnull%2Feasyecc/lists"}