Skip to content

Commit

Permalink
Fix padding issue with Ansible vault for special whars
Browse files Browse the repository at this point in the history
  • Loading branch information
SquirrelDeveloper authored Jul 18, 2024
1 parent 573bbb1 commit 9ee4d4a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ class Vault {
_cipher (secret, id, salt, derivedKey) {
const { key, hmacKey, iv } = derivedKey
const cipherF = crypto.createCipheriv(CIPHER, key, iv)
const ciphertext = Buffer.concat([
cipherF.update(secret),
cipherF.update(pkcs7.pad(secret.length, 16)),
cipherF.final()
])
const finalInput = Buffer.concat([
Buffer.from(secret, 'utf-8'),
pkcs7.pad(Buffer.from(secret, 'utf-8').length, 16),
]);
const ciphertext = Buffer.concat([cipherF.update(finalInput), cipherF.final()]);

const hmac = this._hmac(hmacKey, ciphertext)
const hex = [ salt, hmac, ciphertext ].map(buf => buf.toString('hex')).join('\n')
Expand Down

0 comments on commit 9ee4d4a

Please sign in to comment.