{"id":16486168,"url":"https://github.com/xsc/pandect","last_synced_at":"2025-04-12T18:41:46.076Z","repository":{"id":8486996,"uuid":"10091725","full_name":"xsc/pandect","owner":"xsc","description":"Fast and easy-to-use Message Digest, Checksum and HMAC library for Clojure","archived":false,"fork":false,"pushed_at":"2021-11-17T11:52:14.000Z","size":1531,"stargazers_count":218,"open_issues_count":0,"forks_count":11,"subscribers_count":9,"default_branch":"main","last_synced_at":"2024-04-13T20:16:47.113Z","etag":null,"topics":["checksum","hash","hmac","message-digest","signature"],"latest_commit_sha":null,"homepage":"https://cljdoc.org/d/pandect/pandect/CURRENT","language":"Clojure","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/xsc.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}},"created_at":"2013-05-16T01:57:57.000Z","updated_at":"2023-09-29T03:29:03.000Z","dependencies_parsed_at":"2022-08-24T13:41:17.340Z","dependency_job_id":null,"html_url":"https://github.com/xsc/pandect","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xsc%2Fpandect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xsc%2Fpandect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xsc%2Fpandect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xsc%2Fpandect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xsc","download_url":"https://codeload.github.com/xsc/pandect/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248616958,"owners_count":21134162,"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":["checksum","hash","hmac","message-digest","signature"],"created_at":"2024-10-11T13:28:33.854Z","updated_at":"2025-04-12T18:41:46.039Z","avatar_url":"https://github.com/xsc.png","language":"Clojure","funding_links":[],"categories":["Frameworks and Libs"],"sub_categories":["Clojure"],"readme":"# pandect\n\n[![Clojars Project](https://img.shields.io/clojars/v/pandect.svg)](https://clojars.org/pandect)\n[![Documentation](https://cljdoc.org/badge/pandect/pandect)](https://cljdoc.org/d/pandect/pandect/CURRENT)\n[![CI](https://github.com/xsc/pandect/workflows/CI/badge.svg)](https://github.com/xsc/pandect/actions?query=workflow%3ACI)\n\n__pandect__ is a fast and easy-to-use\n[Message Digest](http://en.wikipedia.org/wiki/Message_digest),\n[Checksum](http://en.wikipedia.org/wiki/Checksum),\n[HMAC](https://en.wikipedia.org/wiki/Hash-based_message_authentication_code)\nand [Signature](https://en.wikipedia.org/wiki/Digital_signature)\nlibrary for Clojure.\n\n## Usage\n\nNote that - for versions 0.6.0 and up - to use functions based on the\nBouncyCastle crypto provider, you have to manually include a version of\nthe `org.bouncycastle/bcprov-jdk15on` artifact. Additionally, you need to take\nspecial care when trying to create an uberjar\n([see here](#uberjars-and-bouncycastle)).\n\n__REPL__\n\n```clojure\n(require '[pandect.algo.sha1 :refer :all])\n\n(sha1 \"Hello World!\")                      ;; =\u003e \"2ef7bde608ce5404e97d5f042f95f89f1c232871\"\n(sha1 (.getBytes \"Hello World!\" \"UTF-8\"))  ;; =\u003e \"2ef7bde608ce5404e97d5f042f95f89f1c232871\"\n(sha1 (File. \"project.clj\"))               ;; =\u003e \"ff3b4565652aeb835edf2715b2a28586929ea4cc\"\n(sha1 (FileInputStream. \"project.clj\"))    ;; =\u003e \"ff3b4565652aeb835edf2715b2a28586929ea4cc\"\n\n;; more variants\n(sha1-bytes \"Hello World!\")                ;; =\u003e #\u003cbyte[] [B@5293b95\u003e\n(sha1-file \"project.clj\")                  ;; =\u003e \"ff3b4565652aeb835edf2715b2a28586929ea4cc\"\n(sha1-file-bytes \"project.clj\")            ;; =\u003e #\u003cbyte[] [B@e2606c7\u003e\n```\n\nHMAC functions take an additional key:\n\n```clojure\n(sha1-hmac \"Hello World!\" \"secret-key\")       ;; =\u003e \"399fc3d94f6df2213f92fcf2a8b6669279ef7d20\"\n(sha1-hmac-bytes \"Hello World!\" \"secret-key\") ;; =\u003e #\u003cbyte[] [B@602bd522\u003e\n```\n\nSigning functions expect a `java.security.PrivateKey`, while verification works\nwith `java.security.PublicKey` or `java.security.cert.Certificate`:\n\n```clojure\n(sha1-rsa \"Hello World!\" private-key)                 ;; =\u003e \"5866...\"\n(sha1-rsa-verify \"Hello World!\" \"5866...\" public-key) ;; =\u003e true\n```\n\nYou can tune stream processing using `pandect.buffer/with-buffer-size` (default\nis 2KB):\n\n```clojure\n(require '[pandect.buffer :refer [with-buffer-size]])\n\n(with-open [in (io/input-stream \"shootout/data/1mb.txt\")]\n  (with-buffer-size (* 512 1024)\n    (sha256 in)))\n```\n\nIf you want to hash a String using a specific encoding, you should create the\nrespective byte array manually:\n\n```clojure\n(sha1 \"Hällo World!\")                          ;; =\u003e \"f19c05a67c3d0f297b62e868657cf177913ce02a\"\n(sha1 (.getBytes \"Hällo World!\" \"ISO-8859-1\")) ;; =\u003e \"cfe670bd6845020f5754b19a3c0eee602043eb89\"\n```\n\nThe namespace `pandect.core` contains all available algorithms but for better\nstartup/compile times, using algorithm-specific ones is recommended.\n\n## Supported Algorithms\n\n\nSee the [generated documentation](https://cljdoc.org/d/pandect/pandect/CURRENT)\nfor the available functions and their parameters.\n\n| Checksum | MDx  | SHA      | SHA-3      | RIPEMD     | BLAKE2      | Others                  |\n|----------|------|----------|------------|------------|-------------|-------------------------|\n| Adler32* | MD2* | SHA-1    | SHA3-224   | RIPEMD-128 | BLAKE2b-160 | SipHash-2-4\u003csup\u003e+\u003c/sup\u003e |\n| CRC-32*  | MD4  | SHA-256  | SHA3-256   | RIPEMD-160 | BLAKE2b-256 | SipHash-4-8\u003csup\u003e+\u003c/sup\u003e |\n|          | MD5  | SHA-384  | SHA3-384   | RIPEMD-256 | BLAKE2b-384 | Tiger192,3              |\n|          |      | SHA-512  | SHA3-512   | RIPEMD-320 | BLAKE2b-512 | Whirlpool               |\n\n\\* not available as MAC\u003cbr /\u003e\n\u003csup\u003e+\u003c/sup\u003e only available as MAC\n\n## Uberjars and BouncyCastle\n\nThe BouncyCastle JAR has been signed to prevent tampering - and JCE won't allow\nusage of any of its functions if that signature is not present. This poses a\nproblem when creating an Uberjar since all needed class files will be extracted\nfrom their JARs and repackaged into a single one - removing any existing\nsignature.\n\nYou'll see, for example, the following exceptions in that case:\n\n```\njava.security.NoSuchAlgorithmException: Algorithm (...) not available\njava.security.NoSuchProviderException: JCE cannot authenticate the provider BC\n```\n\nPrimarily, this means you have to prevent the BouncyCastle files ending up\nwithin the JAR  which can be accomplished using the `:provided` profile in you\n`project.clj`:\n\n```clojure\n:profiles\n{:provided\n {:dependencies [[org.bouncycastle/bcprov-jdk15on \"1.54\"]}}\n```\n\nNow you can build your uberjar but you have to make sure that the BouncyCastle\nJAR is on your classpath when running it, i.e. assuming they are both in the\nsame directory:\n\n```\njava -cp bcprov-jdk15on-1.54.jar:app-standalone.jar app.core\n```\n\nBefore version 0.6.0, pandect accessed the BouncyCastle functionality directly\n(i.e. not via `MessageDigest/getInstance` or `Mac/getInstance` but using actual\nconstructor calls), meaning these limitations did not apply. It is, thus,\nstrongly recommended to do it right and upgrade to 0.6.0.\n\n## Benchmarks\n\nYou can run benchmarks against `pandect`, `buddy` and `clj-digest` using\n[perforate][]:\n\n```sh\nlein bench {--table|--edn}\n```\n\n[perforate]: https://github.com/davidsantiago/perforate\n\n## License\n\n```\nMIT License\n\nCopyright (c) 2014-2021 Yannick Scherer\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxsc%2Fpandect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxsc%2Fpandect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxsc%2Fpandect/lists"}