{"id":20566236,"url":"https://github.com/telkomdev/crypsi-mysql-udf","last_synced_at":"2026-04-29T16:36:31.067Z","repository":{"id":191569595,"uuid":"684746409","full_name":"telkomdev/crypsi-mysql-udf","owner":"telkomdev","description":"C Crypsi (https://github.com/telkomdev/c-crypsi) for MySQL and MariaDB UDF (User Defined Function)","archived":false,"fork":false,"pushed_at":"2023-09-11T07:35:03.000Z","size":56,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-01T01:37:55.773Z","etag":null,"topics":["aes","aes-encryption","c","crypto","mariadb","mysql","mysql-udf"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","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-29T19:12:39.000Z","updated_at":"2023-09-22T11:22:15.000Z","dependencies_parsed_at":"2024-11-16T05:01:36.741Z","dependency_job_id":null,"html_url":"https://github.com/telkomdev/crypsi-mysql-udf","commit_stats":null,"previous_names":["telkomdev/crypsi-mysql-udf"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/telkomdev/crypsi-mysql-udf","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/telkomdev%2Fcrypsi-mysql-udf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/telkomdev%2Fcrypsi-mysql-udf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/telkomdev%2Fcrypsi-mysql-udf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/telkomdev%2Fcrypsi-mysql-udf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/telkomdev","download_url":"https://codeload.github.com/telkomdev/crypsi-mysql-udf/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/telkomdev%2Fcrypsi-mysql-udf/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273279723,"owners_count":25077318,"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","status":"online","status_checked_at":"2025-09-02T02:00:09.530Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-encryption","c","crypto","mariadb","mysql","mysql-udf"],"created_at":"2024-11-16T04:40:42.648Z","updated_at":"2026-04-29T16:36:31.018Z","avatar_url":"https://github.com/telkomdev.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# crypsi-mysql-udf\n\nC Crypsi (https://github.com/telkomdev/c-crypsi) MySQL UDF (User Defined Function)\n\n[![crypsi-mysql-udf CI](https://github.com/telkomdev/crypsi-mysql-udf/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/telkomdev/crypsi-mysql-udf/actions/workflows/ci.yml)\n\n## Motivation/ Why ?\nWhy not `standard mysql crypto function` https://dev.mysql.com/doc/refman/8.0/en/encryption-functions.html ?. At the time this plugin was created, `standard mysql crypto function` did not support `AES GCM` and `HMAC (hash-based message authentication code)` yet. So this plugin is made to fulfill `AES GCM` and `HMAC (hash-based message authentication code)` needs.\n\n## Dependencies\n- https://github.com/telkomdev/c-crypsi\n- Openssl 1.1.1\n\n### `crypsi-mysql-udf` 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- PostgreSQL https://github.com/telkomdev/pgcrypsi\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 `crypsi-mysql-udf`\n\ncrypsi-mysql-udf\n```sql\nmysql\u003e select mcrypsi_aes_128_gcm_encrypt('abc$#128djdyAgbj', 'this is dark') as res;\n+----------------------------------------------------------------------------------+\n| res                                                                              |\n+----------------------------------------------------------------------------------+\n| c5cbfb20cbd635fed539adedb588d64b05458aef3898e1be5225dab28ca96607f721601641cd996d |\n+----------------------------------------------------------------------------------+\n1 row in set (0.01 sec)\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', 'c5cbfb20cbd635fed539adedb588d64b05458aef3898e1be5225dab28ca96607f721601641cd996d');\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/crypsi-mysql-udf.git\n```\n\nInstall MySQL Development client\n```shell\n$ sudo apt-get update\n$ sudo apt-get install libmysqlclient-dev\n```\n\nCompile extensions, Create and Copy SHARED Library to `/usr/lib/mysql/plugin/`\n```shell\n$ cc -fPIC -c crypsi_mysqludf.c -I /usr/include/mysql\n$ cc -shared -o crypsi_mysqludf.so crypsi_mysqludf.o\n$ sudo cp crypsi_mysqludf.so  /usr/lib/mysql/plugin/\n```\n\n#### Notes\nTo find out what `plugin_dir` is referring to, run the following command:\n```shell\nmysql\u003e show variables like 'plugin_dir';\n+---------------+------------------------+\n| Variable_name | Value                  |\n+---------------+------------------------+\n| plugin_dir    | /usr/lib/mysql/plugin/ |\n+---------------+------------------------+\n1 row in set (0.00 sec)\n```\n\n#### Error: Error Code: 1127. Can't find symbol 'xxxx' in library\ntry to restart MySQL Server\n```shell\n$ sudo systemctl restart mysql\n```\n\n### Install to Database\n\nLogin as superuser\n```shell\n$ sudo mysql\n```\n\nShow installed functions\n```shell\n$ select * from mysql.func;\n```\n\nDrop the functions if exists\n```sql\nDROP FUNCTION mcrypsi_aes_128_gcm_encrypt;\nDROP FUNCTION mcrypsi_aes_192_gcm_encrypt;\nDROP FUNCTION mcrypsi_aes_256_gcm_encrypt;\n\nDROP FUNCTION mcrypsi_aes_128_gcm_decrypt;\nDROP FUNCTION mcrypsi_aes_192_gcm_decrypt;\nDROP FUNCTION mcrypsi_aes_256_gcm_decrypt;\n\nDROP FUNCTION mcrypsi_hmac_md5;\nDROP FUNCTION mcrypsi_hmac_sha1;\nDROP FUNCTION mcrypsi_hmac_sha256;\nDROP FUNCTION mcrypsi_hmac_sha384;\nDROP FUNCTION mcrypsi_hmac_sha512;\n```\n\nCreate functions\n```sql\nCREATE FUNCTION mcrypsi_aes_128_gcm_encrypt RETURNS STRING SONAME 'crypsi_mysqludf.so';\nCREATE FUNCTION mcrypsi_aes_192_gcm_encrypt RETURNS STRING SONAME 'crypsi_mysqludf.so';\nCREATE FUNCTION mcrypsi_aes_256_gcm_encrypt RETURNS STRING SONAME 'crypsi_mysqludf.so';\n\nCREATE FUNCTION mcrypsi_aes_128_gcm_decrypt RETURNS STRING SONAME 'crypsi_mysqludf.so';\nCREATE FUNCTION mcrypsi_aes_192_gcm_decrypt RETURNS STRING SONAME 'crypsi_mysqludf.so';\nCREATE FUNCTION mcrypsi_aes_256_gcm_decrypt RETURNS STRING SONAME 'crypsi_mysqludf.so';\n\nCREATE FUNCTION mcrypsi_hmac_md5 RETURNS STRING SONAME 'crypsi_mysqludf.so';\nCREATE FUNCTION mcrypsi_hmac_sha1 RETURNS STRING SONAME 'crypsi_mysqludf.so';\nCREATE FUNCTION mcrypsi_hmac_sha256 RETURNS STRING SONAME 'crypsi_mysqludf.so';\nCREATE FUNCTION mcrypsi_hmac_sha384 RETURNS STRING SONAME 'crypsi_mysqludf.so';\nCREATE FUNCTION mcrypsi_hmac_sha512 RETURNS STRING SONAME 'crypsi_mysqludf.so';\n```\n\n### AES GCM encrypt function\n- mcrypsi_aes_128_gcm_encrypt (AES 128 bit encryption function)\n- mcrypsi_aes_192_gcm_encrypt (AES 192 bit encryption function)\n- mcrypsi_aes_256_gcm_encrypt (AES 256 bit encryption function)\n\n### AES GCM decrypt function\n- mcrypsi_aes_128_gcm_decrypt (AES 128 bit decryption function)\n- mcrypsi_aes_192_gcm_decrypt (AES 192 bit decryption function)\n- mcrypsi_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### HMAC (hash-based message authentication code)\n\nThe length of the HMAC key must be at least 32 characters\n- mcrypsi_hmac_md5\n- mcrypsi_hmac_sha1\n- mcrypsi_hmac_sha256\n- mcrypsi_hmac_sha384\n- mcrypsi_hmac_sha512\n\n### Run test\n```shell\n$ sudo mysql\nmysql\u003e source /home/vagrant/crypsi-mysql-udf/test.sql\n```\n\n### Test the extensions\n\nEncrypt\n```shell\nmysql\u003e select mcrypsi_aes_128_gcm_encrypt('abc$#128djdyAgbj', 'this is dark') as res;\n+----------------------------------------------------------------------------------+\n| res                                                                              |\n+----------------------------------------------------------------------------------+\n| 2d66dcffd5056b67b1cbf276359bd33a3e982047ace8a6c7f6fa1deccee26f1cfd4cc1c8c6d7b15b |\n+----------------------------------------------------------------------------------+\n1 row in set (0.01 sec)\n```\n\nDecrypt\n```shell\nmysql\u003e select mcrypsi_aes_128_gcm_decrypt('abc$#128djdyAgbj', '2d66dcffd5056b67b1cbf276359bd33a3e982047ace8a6c7f6fa1deccee26f1cfd4cc1c8c6d7b15b') as res;\n+--------------+\n| res          |\n+--------------+\n| this is dark |\n+--------------+\n1 row in set (0.01 sec)\n```\n\nHMAC (hash-based message authentication code)\n```shell\nmysql\u003e select mcrypsi_hmac_sha512('abc$#128djdyAgbjau\u0026YAnmcbagryt5x', 'hello world') as res;\n+----------------------------------------------------------------------------------------------------------------------------------+\n| res                                                                                                                              |\n+----------------------------------------------------------------------------------------------------------------------------------+\n| 825b6b87adf4ab749b769425d583dc42cbae2f44381fbf0182b46cab6c6ddf157ea98f58bc735e532d0591e2a99d903811f94ade78159ec678efebc473d088a8 |\n+----------------------------------------------------------------------------------------------------------------------------------+\n1 row in set (0.00 sec)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftelkomdev%2Fcrypsi-mysql-udf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftelkomdev%2Fcrypsi-mysql-udf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftelkomdev%2Fcrypsi-mysql-udf/lists"}