diff --git a/src/common/crypto/cipherBlock.c b/src/common/crypto/cipherBlock.c
index 9a465ca876..5db68399eb 100644
--- a/src/common/crypto/cipherBlock.c
+++ b/src/common/crypto/cipherBlock.c
@@ -11,12 +11,23 @@ Block Cipher
 #include "common/crypto/cipherBlock.h"
 #include "common/crypto/common.h"
 #include "common/crypto/common.intern.h"
+#include "common/crypto/hash.h"
 #include "common/debug.h"
 #include "common/io/filter/filter.h"
 #include "common/log.h"
 #include "common/type/convert.h"
 #include "common/type/object.h"
 
+/***********************************************************************************************************************************
+Key check stored before the salt, the first bytes of an HMAC of the salt with the key. An incorrect key fails validation before
+anything is decrypted.
+***********************************************************************************************************************************/
+#define CIPHER_BLOCK_KEY_CHECK_SIZE                                 4
+
+// Max size of everything before the content: the magic, the key check, and the salt
+#define CIPHER_BLOCK_HEADER_SIZE_MAX                                                                                               \
+    (CIPHER_BLOCK_MAGIC_SIZE + PKCS5_SALT_LEN + CIPHER_BLOCK_KEY_CHECK_SIZE)
+
 /***********************************************************************************************************************************
 Object type
 ***********************************************************************************************************************************/
@@ -24,11 +35,12 @@ typedef struct CipherBlock
 {
     CipherMode mode;                                                // Mode encrypt/decrypt
     bool raw;                                                       // Omit header magic to save space
+    bool keyCheck;                                                  // Is a key check stored before the salt?
     bool saltDone;                                                  // Has the salt been read/generated?
     bool processDone;                                               // Has any data been processed?
     const Buffer *pass;                                             // Passphrase used to generate encryption key
     size_t headerSize;                                              // Size of header read during decrypt
-    uint8_t header[CIPHER_BLOCK_MAGIC_SIZE + PKCS5_SALT_LEN];       // Buffer to hold partial header during decrypt
+    uint8_t header[CIPHER_BLOCK_HEADER_SIZE_MAX];                   // Buffer to hold partial header during decrypt
     const EVP_CIPHER *cipher;                                       // Cipher object
     const EVP_MD *digest;                                           // Message digest object
     EVP_CIPHER_CTX *cipherContext;                                  // Encrypt/decrypt context
@@ -71,6 +83,36 @@ cipherBlockFreeResource(THIS_VOID)
     FUNCTION_LOG_RETURN_VOID();
 }
 
+/***********************************************************************************************************************************
+Generate the key check for a key and salt
+***********************************************************************************************************************************/
+static void
+cipherBlockKeyCheck(const CipherBlock *const this, const uint8_t *const key, const uint8_t *const salt, uint8_t *const keyCheck)
+{
+    FUNCTION_TEST_BEGIN();
+        FUNCTION_TEST_PARAM_P(VOID, this);
+        FUNCTION_TEST_PARAM_P(VOID, key);
+        FUNCTION_TEST_PARAM_P(VOID, salt);
+        FUNCTION_TEST_PARAM_P(VOID, keyCheck);
+    FUNCTION_TEST_END();
+
+    ASSERT(this != NULL);
+    ASSERT(key != NULL);
+    ASSERT(salt != NULL);
+    ASSERT(keyCheck != NULL);
+
+    MEM_CONTEXT_TEMP_BEGIN()
+    {
+        const Buffer *const hmac = cryptoHmacOne(
+            hashTypeSha256, BUF(key, (size_t)EVP_CIPHER_key_length(this->cipher)), BUF(salt, PKCS5_SALT_LEN));
+
+        memcpy(keyCheck, bufPtrConst(hmac), CIPHER_BLOCK_KEY_CHECK_SIZE);
+    }
+    MEM_CONTEXT_TEMP_END();
+
+    FUNCTION_TEST_RETURN_VOID();
+}
+
 /***********************************************************************************************************************************
 Determine how large the destination buffer should be
 ***********************************************************************************************************************************/
@@ -89,7 +131,7 @@ cipherBlockProcessSize(const CipherBlock *const this, const size_t sourceSize)
 
     // On encrypt the header size must be included before the first block
     if (this->mode == cipherModeEncrypt && !this->saltDone)
-        destinationSize += CIPHER_BLOCK_MAGIC_SIZE + PKCS5_SALT_LEN;
+        destinationSize += CIPHER_BLOCK_MAGIC_SIZE + PKCS5_SALT_LEN + (this->keyCheck ? CIPHER_BLOCK_KEY_CHECK_SIZE : 0);
 
     FUNCTION_LOG_RETURN(SIZE, destinationSize);
 }
@@ -118,6 +160,7 @@ cipherBlockProcessBlock(CipherBlock *const this, const uint8_t *source, size_t s
     if (!this->saltDone)
     {
         const uint8_t *salt = NULL;
+        uint8_t *keyCheckDestination = NULL;
 
         // On encrypt the salt is generated
         if (this->mode == cipherModeEncrypt)
@@ -130,6 +173,14 @@ cipherBlockProcessBlock(CipherBlock *const this, const uint8_t *source, size_t s
                 destinationSize += CIPHER_BLOCK_MAGIC_SIZE;
             }
 
+            // Leave space for the key check. It is generated after the key.
+            if (this->keyCheck)
+            {
+                keyCheckDestination = destination;
+                destination += CIPHER_BLOCK_KEY_CHECK_SIZE;
+                destinationSize += CIPHER_BLOCK_KEY_CHECK_SIZE;
+            }
+
             // Add salt to the destination buffer
             cryptoRandomBytes(destination, PKCS5_SALT_LEN);
             salt = destination;
@@ -140,13 +191,15 @@ cipherBlockProcessBlock(CipherBlock *const this, const uint8_t *source, size_t s
         else if (sourceSize > 0)
         {
             // Check if the entire header has been read
-            const size_t headerExpected = this->raw ? PKCS5_SALT_LEN : CIPHER_BLOCK_MAGIC_SIZE + PKCS5_SALT_LEN;
+            const size_t headerExpected =
+                (this->raw ? 0 : CIPHER_BLOCK_MAGIC_SIZE) + PKCS5_SALT_LEN + (this->keyCheck ? CIPHER_BLOCK_KEY_CHECK_SIZE : 0);
 
             if (this->headerSize + sourceSize >= headerExpected)
             {
                 // Copy header (or remains of header) from source into the header buffer
                 memcpy(this->header + this->headerSize, source, headerExpected - this->headerSize);
-                salt = this->header + (this->raw ? 0 : CIPHER_BLOCK_MAGIC_SIZE);
+                salt =
+                    this->header + (this->raw ? 0 : CIPHER_BLOCK_MAGIC_SIZE) + (this->keyCheck ? CIPHER_BLOCK_KEY_CHECK_SIZE : 0);
 
                 // Advance source and source size by the number of bytes read
                 source += headerExpected - this->headerSize;
@@ -180,6 +233,22 @@ cipherBlockProcessBlock(CipherBlock *const this, const uint8_t *source, size_t s
                     this->cipher, this->digest, salt, bufPtrConst(this->pass), (int)bufSize(this->pass), 1, key, initVector) == 0,
                 "unable to generate key and initialization vector");
 
+            // Write the key check before the salt on encrypt and compare it to the key check before the salt on decrypt
+            if (this->keyCheck)
+            {
+                if (this->mode == cipherModeEncrypt)
+                    cipherBlockKeyCheck(this, key, salt, keyCheckDestination);
+                else
+                {
+                    uint8_t keyCheck[CIPHER_BLOCK_KEY_CHECK_SIZE];
+
+                    cipherBlockKeyCheck(this, key, salt, keyCheck);
+
+                    if (memcmp(salt - CIPHER_BLOCK_KEY_CHECK_SIZE, keyCheck, CIPHER_BLOCK_KEY_CHECK_SIZE) != 0)
+                        THROW(CryptoError, "cipher passphrase does not match");
+                }
+            }
+
             // Create context to track cipher
             cryptoError(!(this->cipherContext = EVP_CIPHER_CTX_new()), "unable to create context");
 
@@ -384,12 +453,14 @@ cipherBlockNew(const CipherMode mode, const CipherSpec *const cipherSpec, const
         FUNCTION_LOG_PARAM(STRING_ID, mode);
         FUNCTION_LOG_PARAM(CIPHER_SPEC, cipherSpec);
         FUNCTION_LOG_PARAM(ENUM, param.header);
+        FUNCTION_LOG_PARAM(BOOL, param.keyCheck);
     FUNCTION_LOG_END();
 
     ASSERT(cipherSpec != NULL);
     ASSERT(cipherSpecType(cipherSpec) != cipherTypeNone);
     ASSERT(cipherSpecDigest(cipherSpec) != 0);
     ASSERT(cipherSpecPass(cipherSpec) != NULL && !bufEmpty(cipherSpecPass(cipherSpec)));
+    ASSERT(!param.keyCheck || param.header == cipherBlockHeaderNone);
 
     // Init crypto subsystem
     cryptoInit();
@@ -413,6 +484,7 @@ cipherBlockNew(const CipherMode mode, const CipherSpec *const cipherSpec, const
         {
             .mode = mode,
             .raw = param.header == cipherBlockHeaderNone,
+            .keyCheck = param.keyCheck,
             .cipher = cipher,
             .digest = digest,
             .pass = bufDup(cipherSpecPass(cipherSpec)),
@@ -430,6 +502,7 @@ cipherBlockNew(const CipherMode mode, const CipherSpec *const cipherSpec, const
         pckWriteU64P(packWrite, mode);
         cipherSpecPack(packWrite, cipherSpec);
         pckWriteU32P(packWrite, param.header);
+        pckWriteBoolP(packWrite, param.keyCheck);
         pckWriteEndP(packWrite);
 
         paramList = pckMove(pckWriteResult(packWrite), memContextPrior());
@@ -454,8 +527,9 @@ cipherBlockNewPack(const Pack *const paramList)
         const CipherMode cipherMode = (CipherMode)pckReadU64P(paramListPack);
         const CipherSpec *const cipherSpec = cipherSpecNewPack(paramListPack);
         const CipherBlockHeader header = (CipherBlockHeader)pckReadU32P(paramListPack);
+        const bool keyCheck = pckReadBoolP(paramListPack);
 
-        result = ioFilterMove(cipherBlockNewP(cipherMode, cipherSpec, .header = header), memContextPrior());
+        result = ioFilterMove(cipherBlockNewP(cipherMode, cipherSpec, .header = header, .keyCheck = keyCheck), memContextPrior());
     }
     MEM_CONTEXT_TEMP_END();
 
diff --git a/src/common/crypto/cipherBlock.h b/src/common/crypto/cipherBlock.h
index 80453b2bb2..33e4e1a7e5 100644
--- a/src/common/crypto/cipherBlock.h
+++ b/src/common/crypto/cipherBlock.h
@@ -35,6 +35,7 @@ typedef struct CipherBlockNewParam
 {
     VAR_PARAM_HEADER;
     CipherBlockHeader header;                                       // What precedes the content, the magic by default
+    bool keyCheck;                                                  // Is a key check stored before the salt? Header must be none.
 } CipherBlockNewParam;
 
 #define cipherBlockNewP(mode, cipherSpec, ...)                                                                                     \
diff --git a/src/common/format/cipherBlockFormat.c b/src/common/format/cipherBlockFormat.c
index 9afddb0f41..949e0160ba 100644
--- a/src/common/format/cipherBlockFormat.c
+++ b/src/common/format/cipherBlockFormat.c
@@ -26,7 +26,7 @@ reader that could not see the format in advance would have to decrypt to learn w
 The header takes the place of the salted magic, which is why the content behind it is encrypted raw. Both are eight bytes followed
 by the salt, so the eight bytes are consumed either way and what follows begins with the salt no matter which was there. It also
 means a file of either kind is opened with the openssl command-line tool the same way: replace the first eight bytes with the magic
-that tool expects.
+that tool expects. A file with a key check has it between the header and the salt, so the first twelve bytes are replaced instead.
 
 A file that begins with the magic rather than the header was written at format 5, the only format there was before the header, so
 that is not an error when a header was expected.
@@ -36,6 +36,8 @@ comes first so it is always in the same place, which is how a version decides wh
 checked once the format turns out to be readable, and it must be valid for this version.
 
 If a key id is indicated by the marker, there is first a byte to indicate the length of the key id and then the key id as a string.
+Otherwise the block cipher stores a key check before the salt. A key id selects a key from a map and is never user-supplied, so only
+a file encrypted with the user passphrase has a key check.
 ***********************************************************************************************************************************/
 #define CIPHER_BLOCK_FORMAT_MAGIC                                   "PGBR"
 #define CIPHER_BLOCK_FORMAT_MAGIC_SIZE                              (sizeof(CIPHER_BLOCK_FORMAT_MAGIC) - 1)
@@ -171,12 +173,15 @@ cipherBlockFormatCipherNew(CipherBlockFormat *const this)
     }
     MEM_CONTEXT_TEMP_END();
 
-    // Decrypt raw since the format header has already been parsed
+    // Decrypt raw since the format header has already been parsed. Format >= 6 without a key id has a key check.
     MEM_CONTEXT_OBJ_BEGIN(this)
     {
         this->cipherBlock = cipherBlockNewP(
             cipherModeDecrypt, cipherSpecDupP(cipherSpec, .digestDefault = repoFormatDigest(this->format)),
-            .header = cipherBlockHeaderNone);
+            .header = cipherBlockHeaderNone,
+            .keyCheck =
+                this->format >= REPOSITORY_FORMAT_6 &&
+                this->header[CIPHER_BLOCK_FORMAT_HEADER_SIZE - 1] == CIPHER_BLOCK_FORMAT_MARKER_NONE);
     }
     MEM_CONTEXT_OBJ_END();
 
@@ -567,14 +572,15 @@ cipherBlockFormatFilterGroupWriteAdd(
 
     if (cipherSpecType(cipherSpec) != cipherTypeNone)
     {
-        // Format >= 6 writes the header in place of the magic and the content behind it is encrypted raw
+        // Format >= 6 writes the header in place of the magic and the content behind it is encrypted raw. Without a key id there is
+        // a key check.
         const bool header = format >= REPOSITORY_FORMAT_6;
 
         ioFilterGroupAdd(
             filterGroup,
             cipherBlockNewP(
                 cipherModeEncrypt, cipherSpecDupP(cipherSpec, .digestDefault = repoFormatDigest(format)),
-                .header = header ? cipherBlockHeaderNone : cipherBlockHeaderMagic));
+                .header = header ? cipherBlockHeaderNone : cipherBlockHeaderMagic, .keyCheck = header && param.keyId == NULL));
 
         // The filter is added after the block cipher so the plaintext header is placed before the cipher output
         if (header)
diff --git a/test/define.yaml b/test/define.yaml
index 530b19e84f..00f216022d 100644
--- a/test/define.yaml
+++ b/test/define.yaml
@@ -384,6 +384,9 @@ unit:
       - common/format/cipherSpecMap
       - common/format/format
 
+    include:
+      - common/crypto/cipherBlock
+
   # --------------------------------------------------------------------------------------------------------------------------------
   - name: common/io/tls
     total: 6
diff --git a/test/spec-rekey.md b/test/spec-rekey.md
index e9f260f8c6..6d0c63eaf0 100644
--- a/test/spec-rekey.md
+++ b/test/spec-rekey.md
@@ -40,7 +40,7 @@ cipher-pass={"1":{"key":"afg...","digest":"sha256"}, ...}
 - The digest belongs to the entry rather than to the file. An id 0 key derives with SHA-1 and every format 6 key derives with SHA-256, so the scalar `cipher-digest` written by the format 6 infrastructure commit moves into the entries. This also survives a future format that changes the digest again, which a scalar would not.
 - Keys are held in memory as a new `CipherSpecMap` in `common/format`, keyed by the id, which is what `CipherBlockFormat` selects from and what the read path packs for the protocol. It lives beside the format rather than in `common/crypto` so the block cipher stays free of repository concepts.
 - `Info` holds a `CipherSpecMap` at every format. A format 5 file loads its single scalar key as the one entry, so only the loader and the saver branch on format and nothing above them does.
-- Neither info file carries a key id of its own, since both are encrypted with `repo-cipher-pass` and the map holds only the sub-keys for dependent files. Their header stays eight bytes with the `_` marker, so replacing those bytes with `Salted__` still hands the file to `openssl enc` for a user who wants to read it by hand. A format 6 info file needs `-md sha256` where format 5 needed `-md sha1`. WAL is not worth the same treatment: between the id in front and the key map there is no realistic manual path, and there never was much of one.
+- Neither info file carries a key id of its own, since both are encrypted with `repo-cipher-pass` and the map holds only the sub-keys for dependent files. Their header stays eight bytes with the `_` marker. A four byte key check precedes the salt, the first bytes of an HMAC-SHA256 of the salt with the derived key, so a wrong passphrase is a definite `CryptoError` before anything is decrypted rather than a padding error at flush or, about once in 256, random bytes that fail later as a parse or checksum error. To read a file by hand with `openssl enc`, replace the header and the key check, the first twelve bytes, with `Salted__`. A format 6 info file needs `-md sha256` where format 5 needed `-md sha1`. A file with a key id has no key check since the id selects a key from a map and a wrong key there is a bug rather than a configuration error. WAL is not worth the same treatment: between the id in front and the key map there is no realistic manual path, and there never was much of one.
 
 ## Backup Set Key
 
diff --git a/test/src/module/common/cryptoTest.c b/test/src/module/common/cryptoTest.c
index 0c9a77fcb0..fa06e8624b 100644
--- a/test/src/module/common/cryptoTest.c
+++ b/test/src/module/common/cryptoTest.c
@@ -320,16 +320,19 @@ testRun(void)
         ioFilterFree(blockDecryptFilter);
 
         // -------------------------------------------------------------------------------------------------------------------------
-        TEST_TITLE("encrypt zero byte file with no magic");
+        TEST_TITLE("encrypt zero byte file with no magic and a key check");
 
         blockEncryptFilter = cipherBlockNewP(
-            cipherModeEncrypt, TEST_CIPHER_SPEC(), .header = cipherBlockHeaderNone);
+            cipherModeEncrypt, TEST_CIPHER_SPEC(), .header = cipherBlockHeaderNone, .keyCheck = true);
         blockEncrypt = (CipherBlock *)ioFilterDriver(blockEncryptFilter);
 
         bufUsedZero(encryptBuffer);
 
         ioFilterProcessInOut(blockEncryptFilter, NULL, encryptBuffer);
-        TEST_RESULT_UINT(bufUsed(encryptBuffer), 24, "check remaining size");
+        TEST_RESULT_UINT(
+            bufUsed(encryptBuffer),
+            PKCS5_SALT_LEN + CIPHER_BLOCK_KEY_CHECK_SIZE + (size_t)EVP_CIPHER_block_size(blockEncrypt->cipher),
+            "check remaining size");
 
         ioFilterFree(blockEncryptFilter);
 
@@ -340,10 +343,11 @@ testRun(void)
         TEST_ERROR(ioFilterProcessInOut(blockDecryptFilter, encryptBuffer, decryptBuffer), CryptoError, "cipher header invalid");
 
         // -------------------------------------------------------------------------------------------------------------------------
-        TEST_TITLE("decrypt zero byte file with no magic");
+        TEST_TITLE("decrypt zero byte file with no magic and a key check");
 
-        blockDecryptFilter = cipherBlockNewP(
-            cipherModeDecrypt, TEST_CIPHER_SPEC(), .header = cipherBlockHeaderNone);
+        blockDecryptFilter = cipherBlockNewPack(
+            ioFilterParamList(
+                cipherBlockNewP(cipherModeDecrypt, TEST_CIPHER_SPEC(), .header = cipherBlockHeaderNone, .keyCheck = true)));
         blockDecrypt = (CipherBlock *)ioFilterDriver(blockDecryptFilter);
 
         bufUsedZero(decryptBuffer);
@@ -355,6 +359,19 @@ testRun(void)
 
         ioFilterFree(blockDecryptFilter);
 
+        // -------------------------------------------------------------------------------------------------------------------------
+        TEST_TITLE("error on decrypt with a key check for another passphrase");
+
+        blockDecryptFilter = cipherBlockNewP(
+            cipherModeDecrypt, cipherSpecNewP(cipherTypeAes256Cbc, BUFSTRDEF("other"), .digest = hashTypeSha256),
+            .header = cipherBlockHeaderNone, .keyCheck = true);
+
+        TEST_ERROR(
+            ioFilterProcessInOut(blockDecryptFilter, encryptBuffer, decryptBuffer), CryptoError,
+            "cipher passphrase does not match");
+
+        ioFilterFree(blockDecryptFilter);
+
         // Invalid cipher header
         // -------------------------------------------------------------------------------------------------------------------------
         blockDecryptFilter = cipherBlockNewP(cipherModeDecrypt, TEST_CIPHER_SPEC());
diff --git a/test/src/module/common/formatTest.c b/test/src/module/common/formatTest.c
index 347b907ec9..158baddd4a 100644
--- a/test/src/module/common/formatTest.c
+++ b/test/src/module/common/formatTest.c
@@ -104,6 +104,39 @@ testRun(void)
             cipherBlockFormatResult(ioFilterGroupResultP(headerFilterGroup, CIPHER_BLOCK_FORMAT_FILTER_TYPE)),
             REPOSITORY_FORMAT_6, "filter reports the format");
 
+        // -------------------------------------------------------------------------------------------------------------------------
+        TEST_TITLE("a file with no key id has a key check");
+
+        Buffer *const keyCheckResult = bufNew(0);
+        IoWrite *const keyCheckRead = ioBufferWriteNew(keyCheckResult);
+
+        cipherBlockFormatFilterGroupReadAdd(
+            ioWriteFilterGroup(keyCheckRead), cipherSpecNewP(cipherTypeAes256Cbc, BUFSTRDEF("other")));
+        ioWriteOpen(keyCheckRead);
+
+        TEST_ERROR(ioWrite(keyCheckRead, headerBuffer), CryptoError, "cipher passphrase does not match");
+
+        // -------------------------------------------------------------------------------------------------------------------------
+        TEST_TITLE("replacing the header and key check with the magic gives the format openssl reads");
+
+        Buffer *const opensslBuffer = bufNew(0);
+        const size_t opensslSkip = CIPHER_BLOCK_FORMAT_HEADER_SIZE + CIPHER_BLOCK_KEY_CHECK_SIZE;
+
+        bufCat(opensslBuffer, BUFSTRDEF(CIPHER_BLOCK_MAGIC));
+        bufCatSub(opensslBuffer, headerBuffer, opensslSkip, bufUsed(headerBuffer) - opensslSkip);
+
+        Buffer *const opensslResult = bufNew(0);
+        IoWrite *const opensslRead = ioBufferWriteNew(opensslResult);
+
+        cipherBlockFilterGroupAdd(
+            ioWriteFilterGroup(opensslRead), cipherModeDecrypt,
+            cipherSpecDupP(cipherSpec, .digestDefault = repoFormatDigest(REPOSITORY_FORMAT_6)));
+        ioWriteOpen(opensslRead);
+        ioWrite(opensslRead, opensslBuffer);
+        ioWriteClose(opensslRead);
+
+        TEST_RESULT_STR_Z(strNewBuf(opensslResult), TEST_PLAINTEXT, "content decrypted");
+
         // -------------------------------------------------------------------------------------------------------------------------
         TEST_TITLE("content is handed on in pieces when the destination cannot take it whole");
 
@@ -356,14 +389,11 @@ testRun(void)
         Buffer *const digestBuffer = bufNew(0);
         IoWrite *const digestWrite = ioBufferWriteNew(digestBuffer);
 
-        cipherBlockFormatFilterGroupWriteAddP(ioWriteFilterGroup(digestWrite), keySpecOld, REPOSITORY_FORMAT_5);
+        cipherBlockFormatFilterGroupWriteAddP(ioWriteFilterGroup(digestWrite), keySpecOld, REPOSITORY_FORMAT_6);
         ioWriteOpen(digestWrite);
         ioWrite(digestWrite, testPlainText);
         ioWriteClose(digestWrite);
 
-        // Replace the magic with a format 6 header, which leaves content that only the SHA-1 key can decrypt
-        memcpy(bufPtr(digestBuffer), CIPHER_BLOCK_FORMAT_MAGIC "006_", CIPHER_BLOCK_FORMAT_HEADER_SIZE);
-
         Buffer *const digestResult = bufNew(0);
         IoWrite *const digestRead = ioBufferWriteNew(digestResult);
 
