mirror of
https://github.com/markqvist/Reticulum.git
synced 2024-11-22 21:50:18 +00:00
Added Android compatibility to AES proxy class
This commit is contained in:
parent
5158613501
commit
3d979e2d65
@ -21,6 +21,7 @@
|
|||||||
# SOFTWARE.
|
# SOFTWARE.
|
||||||
|
|
||||||
import RNS.Cryptography.Provider as cp
|
import RNS.Cryptography.Provider as cp
|
||||||
|
import RNS.vendor.platformutils as pu
|
||||||
|
|
||||||
if cp.PROVIDER == cp.PROVIDER_INTERNAL:
|
if cp.PROVIDER == cp.PROVIDER_INTERNAL:
|
||||||
from .aes import AES
|
from .aes import AES
|
||||||
@ -28,6 +29,9 @@ if cp.PROVIDER == cp.PROVIDER_INTERNAL:
|
|||||||
elif cp.PROVIDER == cp.PROVIDER_PYCA:
|
elif cp.PROVIDER == cp.PROVIDER_PYCA:
|
||||||
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
||||||
|
|
||||||
|
if pu.cryptography_old_api():
|
||||||
|
from cryptography.hazmat.backends import default_backend
|
||||||
|
|
||||||
|
|
||||||
class AES_128_CBC:
|
class AES_128_CBC:
|
||||||
|
|
||||||
@ -38,7 +42,11 @@ class AES_128_CBC:
|
|||||||
return cipher.encrypt(plaintext, iv)
|
return cipher.encrypt(plaintext, iv)
|
||||||
|
|
||||||
elif cp.PROVIDER == cp.PROVIDER_PYCA:
|
elif cp.PROVIDER == cp.PROVIDER_PYCA:
|
||||||
|
if not pu.cryptography_old_api():
|
||||||
cipher = Cipher(algorithms.AES(key), modes.CBC(iv))
|
cipher = Cipher(algorithms.AES(key), modes.CBC(iv))
|
||||||
|
else:
|
||||||
|
cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=default_backend())
|
||||||
|
|
||||||
encryptor = cipher.encryptor()
|
encryptor = cipher.encryptor()
|
||||||
ciphertext = encryptor.update(plaintext) + encryptor.finalize()
|
ciphertext = encryptor.update(plaintext) + encryptor.finalize()
|
||||||
return ciphertext
|
return ciphertext
|
||||||
@ -50,7 +58,11 @@ class AES_128_CBC:
|
|||||||
return cipher.decrypt(ciphertext, iv)
|
return cipher.decrypt(ciphertext, iv)
|
||||||
|
|
||||||
elif cp.PROVIDER == cp.PROVIDER_PYCA:
|
elif cp.PROVIDER == cp.PROVIDER_PYCA:
|
||||||
|
if not pu.cryptography_old_api():
|
||||||
cipher = Cipher(algorithms.AES(key), modes.CBC(iv))
|
cipher = Cipher(algorithms.AES(key), modes.CBC(iv))
|
||||||
|
else:
|
||||||
|
cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=default_backend())
|
||||||
|
|
||||||
decryptor = cipher.decryptor()
|
decryptor = cipher.decryptor()
|
||||||
plaintext = decryptor.update(ciphertext) + decryptor.finalize()
|
plaintext = decryptor.update(ciphertext) + decryptor.finalize()
|
||||||
return plaintext
|
return plaintext
|
||||||
|
Loading…
Reference in New Issue
Block a user