{"id":15320350,"url":"https://github.com/cocainecong/secret","last_synced_at":"2025-04-15T02:31:59.211Z","repository":{"id":61403231,"uuid":"547956721","full_name":"CocaineCong/secret","owner":"CocaineCong","description":" Provide the interface of symmetric encryption AES/DES/3DES and asymmetric encryption RSA, making your sensitive data easier to desensitize and store.（ 提供 对称加密 AES/DES/3DES 以及非对称加密 RSA 的上层封装接口，让您的敏感数据更加容易脱敏并存储 ）","archived":false,"fork":false,"pushed_at":"2022-11-01T15:22:44.000Z","size":83,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-28T14:21:18.163Z","etag":null,"topics":["3des","aes","des","encrypt","go","golang","rsa"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CocaineCong.png","metadata":{"files":{"readme":"README.EN.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}},"created_at":"2022-10-08T16:37:53.000Z","updated_at":"2024-06-26T13:02:31.000Z","dependencies_parsed_at":"2023-01-21T05:03:57.423Z","dependency_job_id":null,"html_url":"https://github.com/CocaineCong/secret","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CocaineCong%2Fsecret","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CocaineCong%2Fsecret/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CocaineCong%2Fsecret/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CocaineCong%2Fsecret/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CocaineCong","download_url":"https://codeload.github.com/CocaineCong/secret/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248993982,"owners_count":21195287,"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":["3des","aes","des","encrypt","go","golang","rsa"],"created_at":"2024-10-01T09:08:16.791Z","updated_at":"2025-04-15T02:31:58.775Z","avatar_url":"https://github.com/CocaineCong.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Coding Make Secret Secret\n\n\n![banner](https://img.shields.io/aur/maintainer/secret)\n![go-version](https://img.shields.io/github/go-mod/go-version/CocaineCong/secret)\n[![license](https://img.shields.io/github/license/CocaineCong/secret.svg)](LICENSE)\n[![standard-readme compliant](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)\n\n# README\n\n- zh_cn [简体中文](README.md)\n- en [English](README.EN.md)\n\n# Background\nProvide the interface of symmetric encryption AES/DES/3DES and asymmetric encryption RSA, making your sensitive data easier to desensitize and store.\n\n## Table of Contents\n\n- [Install](#install)\n- [Usage](#usage)\n- [Contributing](#contributing)\n\n\n\n## Install\nYou can install this package like this.\n```go\ngo get github.com/CocaineCong/secret\n```\n\n## Usage\n### AES\nWe can use a special string `special sign` and `key` in our code to construct our AES encryption object. \\\n\nIn addition we can specify the length of AES encryption: AES-128, AES-192, AES-256. \\\nAnd the encryption mode: `BCB, CFB, CTR, OFB`. We will add more encryption modes in the future.\n\nWe input specialSign, key, iv (fixed 16 bits), select the encrypted key length, and select the encryption mode. \\\nIf we don't want to input the iv initial vector, we default to 16 bits of the key.\n\n```go\nspecialSign := \"][;,[2psldp0981zx;./\"\nkey := \"458796\" // key \naesEncrypt, _ := NewAesEncrypt(specialSign, key, \"\", AesEncrypt128, AesModeTypeCTR)  //an aes encryption obj\n```\n\nWe will perform a splicing to encrypt based on the `special sign and key` passed in. \\\nWhen decrypting, you only need to use the **same special sign and key** passed in.\n\n```go\nstr := aesEncrypt.SecretEncrypt(\"this is a secret\")\nfmt.Println(str)\nans := aesEncrypt.SecretDecrypt(str)\nfmt.Println(ans)\n```\n\nresult:\n\n```go\n14be940cf428be2f5432018e3c885370029a0412d4b6be2d8fc96f33b02905f4\nthis is a secret\n```\n\nIn this way, we have completed an encryption and decryption. \\\n\n### DES \u0026 3DES\nDES and 3DES do not support so many modes, **because these two algorithms are already insecure,** but they are here to provide you with more choices.\n\nRelatively simple, pass in specialSign and key to construct a DES encryption object\n\n```go\nspecialSign := \"11111111111\"\nkey := \"458796\" // key 密钥\ndes, _ := NewDesEncrypt(specialSign, key)\n```\n\nEncryption and decryption\n\n```go\nstr, err := des.SecretEncrypt(\"this is a secret\")\nif err != nil {\n    fmt.Println(\"Err\", err)\n}\nfmt.Println(str)\nans, _ := des.SecretDecrypt(str)\nfmt.Println(ans)\n```\n\nresult:\n\n```go\n9c0e547c7eae91b2c7d84527fc3170af52ec01a914f9bf60\nthis is a secret\n```\n\n\n### RSA\nRSA we need to specify `the length of the key`, can only select `the specified length of the key`, when building the object, you can input` the name and path of the public and private key`. If no name is input, the default `public key is publish.pem and the private key is private.pem`. If no path is passed in, it will `default to the path of the current working directory`\n\nSpecify an rsa encryption object and save the public and private keys\n\n```go\nrsa := NewRsaEncrypt(RsaBits1024, \"\", \"\", \"\", \"\")\n_ = rsa.SaveRsaKey() // 保存公私钥\n```\n\nEncrypt this statement with the public key\n\n```go\nsecret, _ := rsa.RsaEncrypt(\"this is a secret\", rsa.PublishKeyPath)\nfmt.Println(\"secret\", secret)\n```\n\nNote that what we get after encryption is a `byte type`. If we want a string type, we need to execute the following code to convert it into a string type.\n\n```go\nsrcStr := rsa.EncryptString(secret)\n```\n\nOf course, we also need to pass in byte type for encryption, so we need to convert this string type to byte type.\n\n```go\nsrcByte := rsa.DecryptByte(srcStr)\n```\n\nAfter converting to byte type, we decrypt it\n\n```go\nans, _ := rsa.RsaDecrypt(secret, rsa.PrivateKeyPath)\nfmt.Println(ans)\n```\n\nIt will return a string type.\n\nresult：\n```go\nsrc aUpVbJqOYvcDil7PmGRZ5iaOJ1oAhWE84uqlUZ5REqZFTW/p/enSTrA/dSGC9puHWuVesFTkYAl5dJtfNAHlCdODOP9xzj1gSQVSQblPFxUnRq1DwSgI3Y4ktApicuD26Pm5ViC5rYP9uCqNTo6Ewo1QQhs+c25EVNOzFHijYQ4=\nans this is a secret\n```\n\n## Contributing\nWe very much welcome interested developers to join and maintain this secret package together!\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcocainecong%2Fsecret","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcocainecong%2Fsecret","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcocainecong%2Fsecret/lists"}