Skip to content

Instantly share code, notes, and snippets.

@HarHarLinks
Last active May 26, 2023 15:19
Show Gist options
  • Save HarHarLinks/eb1fdbfddb22c854da05f38885445dda to your computer and use it in GitHub Desktop.
Save HarHarLinks/eb1fdbfddb22c854da05f38885445dda to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# import ...
k = event.key["k"]
key = base64.urlsafe_b64decode(k + "=" * (-len(k) % 4))
iv = base64.urlsafe_b64decode(event.iv + "=" * (-len(event.iv) % 4))
cypher = AES.new(key, AES.MODE_CTR, nonce=iv[:8])
print(cypher.decrypt(response.body))
#!/usr/bin/env bash
# i haven't yet found a base64 tool that decodes unpadded url-safe data all at once
# this is a dirty solution that seems to work with zsh
padded = ${unpadded}$(printf '=%.0s' {1..$(expr $(echo -n ${unpadded} | wc -c) % 4)})
openssl enc -d -aes-256-ctr -in encryptedImage.png.enc -out decryptedImage.png -iv "$(echo -n $padded_iv | basenc --base64url -d | xxd -p )" -K "$(echo -n $padded_k | basenc --base64url -d | xxd -p -c 0)" -p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment