mirror of
				https://github.com/meshtastic/firmware.git
				synced 2025-10-28 23:34:03 +00:00 
			
		
		
		
	 89469fcb88
			
		
	
	
		89469fcb88
		
			
		
	
	
	
	
		
			
			* more userPrefs.h Added PKI Admin keys to userPrefs.h * Update userPrefs.h Allows all 3 PKI keys to be added to userPrefs.h (#4969) * Update NodeDB.cpp Trunk * Update userPrefs.h Changed wording * Create base64_to_hex.py A little tool for converting base64 PKI Keys to decoded byte that userPrefs.h can understand. * more userPrefs.h Added PKI Admin keys to userPrefs.h * Update userPrefs.h Allows all 3 PKI keys to be added to userPrefs.h (#4969) * Update NodeDB.cpp Trunk * Update userPrefs.h Changed wording * Create base64_to_hex.py A little tool for converting base64 PKI Keys to decoded byte that userPrefs.h can understand.
		
			
				
	
	
		
			34 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| import sys
 | |
| import base64
 | |
| 
 | |
| def base64_to_hex_string(b64_string):
 | |
|     try:
 | |
|         # Decode the Base64 string to raw bytes
 | |
|         decoded_bytes = base64.b64decode(b64_string)
 | |
|     except Exception as e:
 | |
|         raise ValueError(f"Invalid Base64 input: {e}")
 | |
|     
 | |
|     # Check if the decoded result is exactly 32 bytes
 | |
|     if len(decoded_bytes) != 32:
 | |
|         raise ValueError("Decoded Base64 input must be exactly 32 bytes.")
 | |
|     
 | |
|     # Convert each byte to its hex representation
 | |
|     hex_values = [f"0x{byte:02x}" for byte in decoded_bytes]
 | |
|     
 | |
|     # Join the formatted hex values with commas
 | |
|     formatted_output = "{ " + ", ".join(hex_values) + " };"
 | |
|     return formatted_output
 | |
| 
 | |
| if __name__ == "__main__":
 | |
|     # Check if a Base64 string was provided in command line arguments
 | |
|     if len(sys.argv) != 2:
 | |
|         print("Usage: python script.py <base64-string>")
 | |
|         sys.exit(1)
 | |
|     
 | |
|     b64_string = sys.argv[1]
 | |
|     try:
 | |
|         formatted_hex = base64_to_hex_string(b64_string)
 | |
|         print(formatted_hex)
 | |
|     except ValueError as e:
 | |
|         print(e)
 |