aes-gcm

AES GCM encryption and decryption: PHP VS C# BouncyCastle

若如初见. 提交于 2021-02-20 03:38:29
问题 I am currently working on transforming my C# AES-GCM cryptography code to PHP. However, after some research, the text encrypted by my PHP system cannot be decrypted by the C# one. I want to know if there is any difference from both codes: C# with BouncyCastle: using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Crypto.Engines; using Org.BouncyCastle.Crypto.Modes; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Security; using System; using System.IO; using System.Text; /

AES GCM encryption and decryption: PHP VS C# BouncyCastle

亡梦爱人 提交于 2021-02-20 03:38:09
问题 I am currently working on transforming my C# AES-GCM cryptography code to PHP. However, after some research, the text encrypted by my PHP system cannot be decrypted by the C# one. I want to know if there is any difference from both codes: C# with BouncyCastle: using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Crypto.Engines; using Org.BouncyCastle.Crypto.Modes; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Security; using System; using System.IO; using System.Text; /

Java AES/GCM/NoPadding encryption does not increment the counter of the IV after doFinal

瘦欲@ 提交于 2021-02-05 09:22:07
问题 When I initialize a Cipher object with the default AES/GCM algorithm, it has a reandom 12 bytes IV but the first 4 byte does not get incremented ater doFinal is called and throws the java.lang.IllegalStateException: Cannot re-use same key and IV for multiple encryptions exception. SecretKey secretKey = ... final Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding"); cipher.init(Cipher.ENCRYPT_MODE, secretKey); byte[] iv1 = encCipher.getIV(); byte[] ctext = encCipher.doFinal("a".getBytes());

Pycrypto AES GCM encryption and Java decryption

删除回忆录丶 提交于 2021-01-27 20:39:04
问题 I'm using Pycryptodome (a PyCrypto fork) to create AES-GCM ciphertexts. I use the following Python code to encrypt: cek = os.urandom(16) nonce = os.urandom(12) cipher = AES.new(cek, AES.MODE_GCM, nonce=nonce, mac_len=16) ciphertext = cipher.encrypt(message) I then pass this to Java to decrypt: byte[] nonce = new byte[12]; Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding"); GCMParameterSpec gcmSpec = new GCMParameterSpec(128, iv); SecretKeySpec secretKeySpec = new SecretKeySpec(cek, "AES"

Android - javax.crypto.AEADBadTagException

半腔热情 提交于 2021-01-27 06:27:16
问题 I'm currently getting an AEADBadTagException when trying to decrypt a file I have encrypted. I have searched pretty much everywhere on stackoverflow and unable to find a solution, and hoping there is just a small mistake I have made or something to do with encoding etc., since GCM is unable to verify the tag that it is generating. I believe the problem is somewhere in the file I am trying to encrypt/decrypt. The same exact code works on an image, however, when I try to encrypt a PDF, it fails

Trying to decrypt with aes-256-gcm with php

让人想犯罪 __ 提交于 2021-01-02 07:19:21
问题 I wondered whether anyone can help, I am using encryption method aes-256-gcm, I can encrypt, but cannot decrypt. Below is my code, can anyone see where I'm going wrong $textToDecrypt = $_POST['message']; $password = '3sc3RLrpd17'; $method = 'aes-256-gcm'; $tag_length = 16; $password = substr(hash('sha256', $password, true), 0, 32); $iv = chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr

Encrypt a big file that does not fit in RAM with AES-GCM

冷暖自知 提交于 2020-12-14 06:30:31
问题 This code works for a file myfile which fits in RAM: import Crypto.Random, Crypto.Cipher.AES # pip install pycryptodome nonce = Crypto.Random.new().read(16) key = Crypto.Random.new().read(16) # in reality, use a key derivation function, etc. ouf of topic here cipher = Crypto.Cipher.AES.new(key, Crypto.Cipher.AES.MODE_GCM, nonce=nonce) out = io.BytesIO() with open('myfile', 'rb') as g: s = g.read() ciphertext, tag = cipher.encrypt_and_digest(s) out.write(nonce) out.write(ciphertext) out.write