Generate a new AES key with the corresponding HMAC key. :rtype: :class:`AESKey`
(self, key_size=DEFAULT_AES_KEY_SIZE)
| 132 | |
| 133 | @classmethod |
| 134 | def generate(self, key_size=DEFAULT_AES_KEY_SIZE): |
| 135 | """ |
| 136 | Generate a new AES key with the corresponding HMAC key. |
| 137 | |
| 138 | :rtype: :class:`AESKey` |
| 139 | """ |
| 140 | if key_size < MINIMUM_AES_KEY_SIZE: |
| 141 | raise ValueError("Unsafe key size: %s" % (key_size)) |
| 142 | |
| 143 | aes_key_bytes = os.urandom(int(key_size / 8)) |
| 144 | aes_key_string = Base64WSEncode(aes_key_bytes) |
| 145 | |
| 146 | hmac_key_bytes = os.urandom(int(key_size / 8)) |
| 147 | hmac_key_string = Base64WSEncode(hmac_key_bytes) |
| 148 | |
| 149 | return AESKey( |
| 150 | aes_key_string=aes_key_string, |
| 151 | hmac_key_string=hmac_key_string, |
| 152 | hmac_key_size=key_size, |
| 153 | mode="CBC", |
| 154 | size=key_size, |
| 155 | ) |
| 156 | |
| 157 | def to_json(self): |
| 158 | """ |