Skip to content

Commit

Permalink
updated_decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
Lungsangg committed Dec 3, 2024
1 parent a42cfdc commit e680f01
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,26 @@

def add_base64_padding(base64_string):
"""Add padding to the Base64 string if necessary."""
missing_padding = len(base64_string) % 4
if missing_padding:
base64_string += '=' * (4 - missing_padding)
if base64_string:
missing_padding = len(base64_string) % 4
if missing_padding:
base64_string += '=' * (4 - missing_padding)
return base64_string

# Retrieve the base64 encoded private key from the environment variable
encoded_key = os.getenv('private_key')

if encoded_key is None:
raise ValueError("Environment variable 'PRIVATE_KEY_BASE64' is not set.")
print("Environment variable 'private_key' is not set. Skipping key decoding process.")
else:
# Add padding to the encoded key
encoded_key = add_base64_padding(encoded_key)

# Add padding to the encoded key
encoded_key = add_base64_padding(encoded_key)

# Decode the private key
try:
private_key = base64.b64decode(encoded_key)
except binascii.Error as e:
raise ValueError(f"Failed to decode Base64 string: {e}")

private_key_1 = private_key.replace(b'\\n', b'\n')
# Decode the private key
try:
private_key = base64.b64decode(encoded_key)
# Replace escaped newlines with actual newlines
private_key_1 = private_key.replace(b'\\n', b'\n')
print("Private key decoded successfully.")
except binascii.Error as e:
raise ValueError(f"Failed to decode Base64 string: {e}")

0 comments on commit e680f01

Please sign in to comment.