Title: fix(ciphers): eliminate static mutable Cipher and bind IV to ciphertext in AESEncryption by Bhumit267 · Pull Request #7767 · TheAlgorithms/Java · GitHub
Open Graph Title: fix(ciphers): eliminate static mutable Cipher and bind IV to ciphertext in AESEncryption by Bhumit267 · Pull Request #7767 · TheAlgorithms/Java
X Title: fix(ciphers): eliminate static mutable Cipher and bind IV to ciphertext in AESEncryption by Bhumit267 · Pull Request #7767 · TheAlgorithms/Java
Description: I have read CONTRIBUTING.md. This pull request is all my own work -- I have not plagiarized it. All filenames are in PascalCase. All functions and variable names follow Java naming conventions. All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations. All new algorithms include a corresponding test class that validates their functionality. All new code is formatted with clang-format -i --style=file path/to/your/file.java Fixes #7763 Description In AESEncryption.java, private static Cipher aesCipher; was stored as a mutable static variable. When decrypting, decryptText() relied on aesCipher.getIV(). This caused several serious issues: IV Cross-Contamination & Tag Mismatch: If encryptText() was called on multiple plaintexts ($M_1, M_2$), aesCipher was updated with the IV generated for $M_2$. Decrypting $M_1$'s ciphertext subsequently failed with javax.crypto.AEADBadTagException: Tag mismatch!. NullPointerException: Calling decryptText() without first running encryptText() in the same JVM session resulted in an NPE because aesCipher was null. Thread Safety & State Leaks: The static state made the cipher unsafe for concurrent usage across threads. Changes Eliminated private static Cipher aesCipher;, making encryption and decryption completely stateless and thread-safe. Standardized AES-GCM IV management by prepending the 12-byte IV to the ciphertext payload (IV || Ciphertext + Tag) and extracting it during decryption. Preserved existing public method signatures (encryptText(String, SecretKey) and decryptText(byte[], SecretKey)). Added regression tests in AESEncryptionTest.java verifying multiple consecutive encryptions/decryptions and validating error handling for short ciphertexts. Verification mvn test -Dtest=AESEncryptionTest passes (7/7 tests pass). mvn checkstyle:check passes with 0 violations.
Open Graph Description: I have read CONTRIBUTING.md. This pull request is all my own work -- I have not plagiarized it. All filenames are in PascalCase. All functions and variable names follow Java naming conventions. ...
X Description: I have read CONTRIBUTING.md. This pull request is all my own work -- I have not plagiarized it. All filenames are in PascalCase. All functions and variable names follow Java naming conventions. ...
Opengraph URL: https://github.com/TheAlgorithms/Java/pull/7767
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:ef61b76f-b6a0-3407-cc4b-778e39b7475a |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | DBD4:313081:105DDB3:15A20DB:6B01DB4E |
| html-safe-nonce | b5a62a28c36bef6ed9d3b05229af418dcf7cf69a8a9001f16f78e93c4c7fb095 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQkQ0OjMxMzA4MToxMDVEREIzOjE1QTIwREI6NkIwMURCNEUiLCJ2aXNpdG9yX2lkIjoiNTkwOTAzMzE5NjA5MTIwMjM4MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4d9c04bc307b9d31cdf5cb0d4f294eeff4b7d0030f3d6164acb3e96d39a1455e |
| hovercard-subject-tag | pull_request:5389211281 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/TheAlgorithms/Java/pull/7767/files |
| twitter:image | https://avatars.githubusercontent.com/u/178378365?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/178378365?s=400&v=4 |
| og:image:alt | I have read CONTRIBUTING.md. This pull request is all my own work -- I have not plagiarized it. All filenames are in PascalCase. All functions and variable names follow Java naming conventions. ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/TheAlgorithms/Java git https://github.com/TheAlgorithms/Java.git |
| octolytics-dimension-user_id | 20487725 |
| octolytics-dimension-user_login | TheAlgorithms |
| octolytics-dimension-repository_id | 63477660 |
| octolytics-dimension-repository_nwo | TheAlgorithms/Java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 63477660 |
| octolytics-dimension-repository_network_root_nwo | TheAlgorithms/Java |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width