{"id":20566239,"url":"https://github.com/telkomdev/pgcrypsi","last_synced_at":"2025-03-06T08:47:09.153Z","repository":{"id":191349817,"uuid":"684444815","full_name":"telkomdev/pgcrypsi","owner":"telkomdev","description":"C Crypsi (https://github.com/telkomdev/c-crypsi) PostgreSQL Extension","archived":false,"fork":false,"pushed_at":"2023-09-11T07:36:43.000Z","size":45,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-16T20:19:02.905Z","etag":null,"topics":["aes","aes-gcm","c","crypto","postgresql-extension"],"latest_commit_sha":null,"homepage":"","language":"C","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/telkomdev.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":"2023-08-29T06:20:20.000Z","updated_at":"2023-08-29T07:17:46.000Z","dependencies_parsed_at":"2024-11-16T04:40:50.463Z","dependency_job_id":"4c1f6c8b-812d-438f-aa0f-80b8b5a95ef3","html_url":"https://github.com/telkomdev/pgcrypsi","commit_stats":null,"previous_names":["telkomdev/pgcrypsi"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/telkomdev%2Fpgcrypsi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/telkomdev%2Fpgcrypsi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/telkomdev%2Fpgcrypsi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/telkomdev%2Fpgcrypsi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/telkomdev","download_url":"https://codeload.github.com/telkomdev/pgcrypsi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242179259,"owners_count":20084940,"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":["aes","aes-gcm","c","crypto","postgresql-extension"],"created_at":"2024-11-16T04:40:43.266Z","updated_at":"2025-03-06T08:47:09.133Z","avatar_url":"https://github.com/telkomdev.png","language":"C","readme":"# pgcrypsi\n\nC Crypsi (https://github.com/telkomdev/c-crypsi) PostgreSQL Extension\n\n[![pgcrypsi CI](https://github.com/telkomdev/pgcrypsi/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/telkomdev/pgcrypsi/actions/workflows/ci.yml)\n\n## Motivation/ Why ?\nWhy not `pgcrypto` ?. At the time this plugin was created, `pgcrypto` did not support `AES GCM` yet. So this plugin is made to fulfill `AES GCM` encryption needs.\n\n## Dependencies\n- https://github.com/telkomdev/c-crypsi\n- Openssl 1.1.1\n\n### `pgcrypsi` is compatible with each other with the following libraries. \n- C/C++ https://github.com/telkomdev/c-crypsi\n- Golang https://github.com/telkomdev/go-crypsi\n- Python https://github.com/telkomdev/pycrypsi\n- C# (.NET) https://github.com/telkomdev/NetCrypsi\n- Java/JVM https://github.com/telkomdev/jcrypsi\n- NodeJs https://github.com/telkomdev/crypsi\n- Javascript (React and Browser) https://github.com/telkomdev/crypsi.js\n- MySQL https://github.com/telkomdev/crypsi-mysql-udf\n\nCompatible which means you can directly use existing functions to encrypt and decrypt data. For example, the functions in the Crypsi package for NodeJs below are compatible with the functions in `pgcrypsi`\n\npgcrypsi\n```sql\npostgres=# select pgcrypsi_aes_128_gcm_encrypt('abc$#128djdyAgbj', 'this is dark') as res;\n                                       res\n----------------------------------------------------------------------------------\n 817352e89687f1786b6c66939011f9714087a85a87c9eca95ea172067e33d6839235848fed0a32f9\n(1 row)\n```\n\nDecrypt the above encrypted data with the crypsi package for Nodejs\n```javascript\nconst { aesEncryption } = require('crypsi');\n\nconst decryptedData = aesEncryption.decryptWithAes128Gcm('abc$#128djdyAgbj', '817352e89687f1786b6c66939011f9714087a85a87c9eca95ea172067e33d6839235848fed0a32f9');\nconsole.log(decryptedData.toString('utf-8')); // result: this is dark\n```\n\n\n## Getting started\n\n### Building\n\nClone\n```shell\n$ git clone https://github.com/telkomdev/pgcrypsi.git\n```\n\nInstall PostgreSQL Development server and client\n```shell\n$ sudo apt install libpq-dev\n$ sudo apt-get install -y postgresql-server-dev-10\n```\n\nCompile extensions, Create and Copy SHARED Library to `/usr/lib/postgresql/10/lib/`\n```shell\n$ cc -fPIC -c pgcrypsi.c -I /usr/include/postgresql/10/server/\n$ cc -shared -o pgcrypsi.so pgcrypsi.o\n$ sudo cp pgcrypsi.so  /usr/lib/postgresql/10/lib/\n```\n\n#### Notes\nTo find out what `$libdir` is referring to, run the following command:\n```shell\n$ pg_config --pkglibdir\n/usr/lib/postgresql/10/lib\n```\n\nInstall extensions\n```shell\n$ sudo make USE_PGXS=1 install\n```\n\n### Install to Database\n\nLogin as superuser\n```shell\n$ sudo --login --user postgres\n$ psql\n```\n\nConnect to specific Database\n```shell\n$ \\c database_name;\n```\n\nShow installed extensions\n```shell\n$ select extname from pg_extension;\n```\n\nDrop extensions\n```shell\n$ DROP EXTENSION IF EXISTS pgcrypsi;\n```\n\nCreate extensions\n```shell\n$ CREATE EXTENSION IF NOT EXISTS pgcrypsi;\n```\n\n### AES GCM encrypt function\n- pgcrypsi_aes_128_gcm_encrypt (AES 128 bit encryption function)\n- pgcrypsi_aes_192_gcm_encrypt (AES 192 bit encryption function)\n- pgcrypsi_aes_256_gcm_encrypt (AES 256 bit encryption function)\n\n### AES GCM decrypt function\n- pgcrypsi_aes_128_gcm_decrypt (AES 128 bit decryption function)\n- pgcrypsi_aes_192_gcm_decrypt (AES 192 bit decryption function)\n- pgcrypsi_aes_256_gcm_decrypt (AES 256 bit decryption function)\n\n### Expected key length\n- AES 128: key length should be 16 bytes/char\n- AES 192: key length should be 24 bytes/char\n- AES 256: key length should be 32 bytes/char\n\n### Run test\n```shell\npostgres=# \\i /home/user/pgcrypsi/test.sql\n```\n\n### Test the extensions\n\nEncrypt\n```shell\npostgres=# select pgcrypsi_aes_256_gcm_encrypt('abc$#128djdyAgbjau\u0026YAnmcbagryt5x', 'this is dark') as res;\n                                       res\n----------------------------------------------------------------------------------\n 90fee206d3f41bd92e45e7c876cce4e3f4ed65aeef3cbd05139677bc18d1b393a53848944ef3df05\n(1 row)\n```\n\nDecrypt\n```shell\npostgres=# select pgcrypsi_aes_256_gcm_decrypt('abc$#128djdyAgbjau\u0026YAnmcbagryt5x', '90fee206d3f41bd92e45e7c876cce4e3f4ed65aeef3cbd05139677bc18d1b393a53848944ef3df05') as res;\n     res\n--------------\n this is dark\n(1 row)\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftelkomdev%2Fpgcrypsi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftelkomdev%2Fpgcrypsi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftelkomdev%2Fpgcrypsi/lists"}