(json)
| 138 | |
| 139 | |
| 140 | def pad_aes_gcm(json): |
| 141 | # AES-GCM encryption leaks length of plaintext, so we pad the object prior to encryption. |
| 142 | result = json |
| 143 | json_bytes = json.encode('UTF-8') if isinstance(json, str) else json |
| 144 | if isinstance(json_bytes, bytes): |
| 145 | bytes_len = len(json_bytes) |
| 146 | padded_len = max(384, bytes_len) |
| 147 | # padded_len = math.ceil(padded_len / 16) * 16 |
| 148 | if padded_len % 16: padded_len = padded_len + 16 - (padded_len % 16) |
| 149 | |
| 150 | if padded_len != bytes_len: |
| 151 | pad_len = abs(padded_len - bytes_len) |
| 152 | pad = ' ' * pad_len # fill with spaces (byte value 0x20) |
| 153 | result = result + pad if isinstance(result, str) else b''.join([result, pad.encode('UTF-8')]) |
| 154 | |
| 155 | return result |
| 156 | |
| 157 | |
| 158 | def decrypt_rsa_key(encrypted_private_key, data_key): |
no outgoing calls
no test coverage detected