You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thank you for making this. I couldn't believe it when I went looking for a TS age implementation, and lo and behold, you had made an official one. Amazing!
My current use case is being able to decrypt pieces of an age-encrypted sops file in JS. We
Here's an example of the kind of thing I want to parse, where I need to decrypt the value key, and my AGE public key is listed as a recipient:
/workspaces/DeepStructure/node_modules/.pnpm/age-encryption@0.1.5/node_modules/age-encryption/dist/format.js:91
throw Error("invalid version " + versionLine);
^
Error: invalid version null
at parseHeader (/workspaces/DeepStructure/node_modules/.pnpm/age-encryption@0.1.5/node_modules/age-encryption/dist/format.js:91:15)
at Decrypter.decrypt (/workspaces/DeepStructure/node_modules/.pnpm/age-encryption@0.1.5/node_modules/age-encryption/dist/index.js:115:19)
at decryptSopsFile (/workspaces/DeepStructure/misc/sops/sops-js/src/sops.ts:20:37)
at main (/workspaces/DeepStructure/misc/sops/sops-js/src/index.ts:32:5)
I played with this some more and was able to get it. I needed to extract the base64 encoded key:
functiongetEncryptionKeyForRecipient(sopsFile: string,privateAgeKey: string){const{ Decrypter }=awaitage();constdoc=awaitloadSopsFile(sopsFile);if(!Array.isArray(doc?.sops?.age)){thrownewError("missing sops age metadata");}constsopsAgeConfig=doc.sops.age;constpubKey=awaitgetPublicAgeKey(privateAgeKey);const{ enc }=sopsAgeConfig.find((config: SopsAgeConfig)=>config.recipient===pubKey);if(!enc){thrownewError("no matching recipient found in age config");}constdecrypter=newDecrypter();decrypter.addIdentity(privateAgeKey);constregex=/-----BEGIN AGE ENCRYPTED FILE-----\s*([\s\S]*?)\s*-----END AGE ENCRYPTED FILE-----/;constmatches=enc.match(regex);if(!(matches&&matches[1])){thrownewError("unable to extract age encryption key");}constbase64String=matches[1].trim();constencrypted=Buffer.from(base64String,"base64");constdecryptionKey=decrypter.decrypt(encrypted,"uint8array");returndecryptionKey;}
I'm surprised that I couldn't use the whole -----BEGIN AGE ENCRYPTED FILE-----... block, but perhaps that's just my own ignorance showing.
Thank you for making this. I couldn't believe it when I went looking for a TS age implementation, and lo and behold, you had made an official one. Amazing!
My current use case is being able to decrypt pieces of an age-encrypted sops file in JS. We
Here's an example of the kind of thing I want to parse, where I need to decrypt the
value
key, and my AGE public key is listed as arecipient
:Here's my first attempt to get that decryption key:
When I run this, I get the following error:
Which seems to be
typage/lib/format.ts
Line 109 in d074454
On my system I'm using:
Do I need to pass more info in order to be able to do this? Use a different version somehow? Or maybe it's not possible?
Thanks for helping me understand what is and isn't possible.
The text was updated successfully, but these errors were encountered: