philiprehberger-crypt 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +13 -0
- data/lib/philiprehberger/crypt/version.rb +1 -1
- data/lib/philiprehberger/crypt.rb +13 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 789ed3adf81e8d52a357a47e485833197aa236ecfd9f66a941648e711bf40133
|
|
4
|
+
data.tar.gz: aa18d2c620b46d7a098843988684da63897b51d38373acdaaf8cafb594ced84b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8c6780048c0399326833092b4af23fb7dcd50162675e85eba91b279f7767f5693259f9a8aea780393fe60516a86e3835e6bc27b70098bd51765d24186f0bbb63
|
|
7
|
+
data.tar.gz: a744e5db314581c1d8f78a30487a1374a2cfe074c7cbc3b6294cb598fe65425b015eb425e4b3b9e745be618a6b8a3c9b1116acb4fd139e39d543b8592ab1da2a
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.5.0] - 2026-05-01
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `Crypt.fingerprint(key)` — produces a short, stable identifier for a key (first 16 hex chars of `SHA-256(key)`). Stable across raw and hex key representations. Useful for log lines, key-id headers, and key rotation audits without leaking key material.
|
|
14
|
+
|
|
10
15
|
## [0.4.0] - 2026-04-15
|
|
11
16
|
|
|
12
17
|
### Added
|
data/README.md
CHANGED
|
@@ -116,6 +116,18 @@ result = Philiprehberger::Crypt.hash_and_hmac('payload', key: key)
|
|
|
116
116
|
result = Philiprehberger::Crypt.hash_and_hmac('payload', key: key, algorithm: :sha512)
|
|
117
117
|
```
|
|
118
118
|
|
|
119
|
+
### Key Fingerprint
|
|
120
|
+
|
|
121
|
+
Generate a short, safe identifier for a key — stable, hex-encoded, and never reveals the key itself.
|
|
122
|
+
Use it in log lines, key-id headers, and key rotation audits.
|
|
123
|
+
|
|
124
|
+
```ruby
|
|
125
|
+
key = Philiprehberger::Crypt.random_hex(16)
|
|
126
|
+
|
|
127
|
+
Philiprehberger::Crypt.fingerprint(key) # => "a3f4b2c1d8e9f0a1"
|
|
128
|
+
# Same value for raw and hex representations of the same key
|
|
129
|
+
```
|
|
130
|
+
|
|
119
131
|
### Secure Comparison
|
|
120
132
|
|
|
121
133
|
```ruby
|
|
@@ -142,6 +154,7 @@ Philiprehberger::Crypt.secure_compare(token_a, token_b)
|
|
|
142
154
|
| `.hash(data, algorithm:)` | Compute hex digest (SHA-256, SHA-384, or SHA-512) |
|
|
143
155
|
| `.hash_and_hmac(data, key:, algorithm:)` | Compute hash and HMAC signature in one call |
|
|
144
156
|
| `.secure_compare(a, b)` | Constant-time string comparison |
|
|
157
|
+
| `.fingerprint(key)` | 16-char hex identifier (`SHA-256(key)[0,16]`) safe for logs and key-id headers |
|
|
145
158
|
| `DecryptionError` | Raised when decryption fails |
|
|
146
159
|
|
|
147
160
|
## Development
|
|
@@ -229,6 +229,19 @@ module Philiprehberger
|
|
|
229
229
|
OpenSSL.fixed_length_secure_compare(a, b)
|
|
230
230
|
end
|
|
231
231
|
|
|
232
|
+
# Produce a short, stable identifier for a key without leaking key material.
|
|
233
|
+
#
|
|
234
|
+
# Returns the first 16 hex characters of `SHA-256(normalized_key)`. Stable
|
|
235
|
+
# across raw and hex representations of the same key. Useful for log lines
|
|
236
|
+
# ("encrypted with key #{Crypt.fingerprint(k)}"), key-id headers, and key
|
|
237
|
+
# rotation audits.
|
|
238
|
+
#
|
|
239
|
+
# @param key [String] a 32-byte raw or 64-character hex key
|
|
240
|
+
# @return [String] 16-character lowercase hex identifier
|
|
241
|
+
def self.fingerprint(key)
|
|
242
|
+
OpenSSL::Digest::SHA256.hexdigest(normalize_key(key))[0, 16]
|
|
243
|
+
end
|
|
244
|
+
|
|
232
245
|
# @api private
|
|
233
246
|
def self.normalize_key(key)
|
|
234
247
|
return key if key.bytesize == KEY_LENGTH
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-crypt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Philip Rehberger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-05-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A high-level encryption toolkit providing AES-256-GCM encryption and
|
|
14
14
|
decryption, key rotation, envelope encryption, PBKDF2 key derivation, secure random
|