Mein Teamkollege hat Kotlin-Code geschrieben, um ZIP-Dateien von der Android-Seite mit AES BC zu verschlüsseln, und ich versuche, ihn zu entschlüsseln. Aber es passiert nicht. Ich muss clientseitigen Python-Code schreiben, um diese Dateien zu entschlüsseln
Dies ist der Kotlin-Code
from Crypto.Cipher import AES
import base64
def get_secret_key():
# This is the same key used in the Android code
secret_key_encoded = "7same key"
decoded_key = base64.b64decode(secret_key_encoded)
return decoded_key
def decrypt_file(input_file_path, output_file_path=None):
try:
# If no output path specified, create one by removing .encrypted extension if present
if output_file_path is None:
output_file_path = input_file_path.replace('.encrypted', '')
if output_file_path == input_file_path:
output_file_path = input_file_path.replace('.zip', '_decrypted.zip')
# Read the encrypted file
with open(input_file_path, 'rb') as file:
encrypted_data = file.read()
# Get the secret key
key = get_secret_key()
# Create cipher object and decrypt the data
cipher = AES.new(key, AES.MODE_CBC, iv=bytes(16)) # 16 bytes of zeros as IV
decrypted_data = cipher.decrypt(encrypted_data)
padding_length = decrypted_data[-1]
decrypted_data = decrypted_data[:-padding_length]
# Write the decrypted data to output file
with open(output_file_path, 'wb') as file:
file.write(decrypted_data)
print(f"File decrypted successfully: {output_file_path}")
return True
except Exception as e:
print(f"Error during decryption: {str(e)}")
return False
# Example usage
if __name__ == "__main__":
# Example usage
encrypted_file_path = "com.android.settings_1736318346774.zip"
decrypt_file(encrypted_file_path)
Mit diesem Code wird die ZIP-Datei generiert, kann aber nicht entpackt werden
Mein Teamkollege hat Kotlin-Code geschrieben, um ZIP-Dateien von der Android-Seite mit AES BC zu verschlüsseln, und ich versuche, ihn zu entschlüsseln. Aber es passiert nicht. Ich muss clientseitigen Python-Code schreiben, um diese Dateien zu entschlüsseln Dies ist der Kotlin-Code [code]import android.util.Base64 import android.util.Log import java.io.BufferedInputStream import java.io.BufferedOutputStream import java.io.File import java.io.FileInputStream import java.io.FileOutputStream import java.security.SecureRandom import javax.crypto.Cipher import javax.crypto.KeyGenerator import javax.crypto.SecretKey import javax.crypto.spec.IvParameterSpec import javax.crypto.spec.SecretKeySpec object AESEncryption { fun generateSecretKey(): SecretKey { val secureRandom = SecureRandom() val keyGenerator = KeyGenerator.getInstance("AES") //generate a key with secure random keyGenerator?.init(256, secureRandom) val key = keyGenerator.generateKey() val secretKeyBase64 = Base64.encodeToString(key.encoded, Base64.NO_WRAP) Log.e("AES KEY", "Generated AES key: $secretKeyBase64") return key }
fun readFile(filePath: String): ByteArray { val file = File(filePath) val fileContents = file.readBytes() val inputBuffer = BufferedInputStream( FileInputStream(file) )
fun getSecretKey(): SecretKey{ val secretKeyEncoded = "key is here" val decodedKey = Base64.decode(secretKeyEncoded, Base64.NO_WRAP) val secretKey = SecretKeySpec(decodedKey, 0, decodedKey.size, "AES") return secretKey }
fun decrypt(yourKey: SecretKey, fileData: ByteArray): ByteArray { val decrypted: ByteArray val cipher = Cipher.getInstance("AES", "BC") cipher.init(Cipher.DECRYPT_MODE, yourKey, IvParameterSpec(ByteArray(cipher.blockSize))) decrypted = cipher.doFinal(fileData) return decrypted }
fun decryptEncryptedFile(filePath: String) { val fileData = readFile(filePath) val secretKey = getSecretKey() val decodedData = decrypt(secretKey, fileData) saveFile(decodedData, "$filePath") } } [/code] und das ist mein Python-Code [code]from Crypto.Cipher import AES import base64
def get_secret_key(): # This is the same key used in the Android code secret_key_encoded = "7same key" decoded_key = base64.b64decode(secret_key_encoded) return decoded_key
def decrypt_file(input_file_path, output_file_path=None): try: # If no output path specified, create one by removing .encrypted extension if present if output_file_path is None: output_file_path = input_file_path.replace('.encrypted', '') if output_file_path == input_file_path: output_file_path = input_file_path.replace('.zip', '_decrypted.zip')
# Read the encrypted file with open(input_file_path, 'rb') as file: encrypted_data = file.read()
# Get the secret key key = get_secret_key()
# Create cipher object and decrypt the data cipher = AES.new(key, AES.MODE_CBC, iv=bytes(16)) # 16 bytes of zeros as IV decrypted_data = cipher.decrypt(encrypted_data)
except Exception as e: print(f"Error during decryption: {str(e)}") return False
# Example usage if __name__ == "__main__": # Example usage encrypted_file_path = "com.android.settings_1736318346774.zip" decrypt_file(encrypted_file_path) [/code] Mit diesem Code wird die ZIP-Datei generiert, kann aber nicht entpackt werden
Mein Teamkollege hat Kotlin-Code geschrieben, um ZIP-Dateien von der Android-Seite mit AES BC zu verschlüsseln, und ich versuche, ihn zu entschlüsseln. Aber es passiert nicht. Ich muss clientseitigen...
Erklärung.
Ich habe ein Problem mit der AES-256-CTR-Entschlüsselung mithilfe der React-native-aes-crypto-Bibliothek. Die Entschlüsselung funktioniert auf Android einwandfrei, schlägt jedoch auf iOS...
Ich habe ein Problem damit, ein Archiv zu erstellen und einen Verzeichniseintrag hinzuzufügen. Mein Code sieht wie folgt aus:
using (var zip = ZipFile.Create(zipPath))
{
if...
Ich habe Visual Studio und eine Reihe von Abhängigkeiten in einem Orchestrator-Funktionsprojekt aktualisiert und plötzlich erhalte ich die Fehlermeldung CS0104:
ILogger ist eine mehrdeutige Referenz...
Wenn ich versuche, eine Zeichenfolgenvariable, die ein codiertes Base64-Bild ist, als Parameter im Junit-Unit-Test zu übergeben, erhalte ich eine NullpointerException. Wenn ich es außerhalb der...