вот код ржавчины:
Код: Выделить всё
/// Encrypts the input plain text with the 32 bytes key and IV.
#[no_mangle]
fn encrypt_ige(plain: &[u8], key: &[u8], iv: &[u8]) -> Vec {
let mut key_array = [0; 32];
key_array.copy_from_slice(key);
let mut iv_array = [0; 32];
iv_array.copy_from_slice(iv);
let cipher = grammers_crypto::encrypt_ige(plain, &key_array, &iv_array);
return cipher;
}
/// Decrypts the input cipher text with the 32 bytes key and IV.
#[no_mangle]
fn decrypt_ige(cipher: &[u8], key: &[u8], iv: &[u8]) -> Vec {
let mut key_array = [0; 32];
key_array.copy_from_slice(key);
let mut iv_array = [0; 32];
iv_array.copy_from_slice(iv);
let plain = grammers_crypto::decrypt_ige(cipher, &key_array, &iv_array);
return plain;
}
/// Factorizes the pair of primes ``pq`` into ``(p, q)``.
#[no_mangle]
fn factorize_pq_pair(pq: u64) -> (u64, u64) {
grammers_crypto::factorize::factorize(pq)
}
Код: Выделить всё
from ctypes import *
def decrypt_ige(cipher_text, key, iv):
cryptg=CDLL('cryptg.dll')
decrpted=cryptg.decrypt_ige(cipher_text,key,iv)
return decrpted
"thread '' запаниковал в src\lib.rs:22:15:
длина исходного фрагмента (400212022800) не соответствует длине целевого среза (32)"
Я проверил, длина ключа и iv равна 32.
Я также пробовал:
Код: Выделить всё
from ctypes import *
def decrypt_ige(cipher_text, key, iv):
raw_ubytes = (ctypes.c_ubyte * len(cipher_text)).from_buffer_copy(cipher_text)
raw_ubytes2 = (ctypes.c_ubyte * len(key)).from_buffer_copy(key)
raw_ubytes3 = (ctypes.c_ubyte * len(iv)).from_buffer_copy(iv)
cryptg=CDLL('cryptg.dll')
decrpted=cryptg.decrypt_ige(raw_ubytes,raw_ubytes2,raw_ubytes3)
return decrpted
"thread '' запаниковал в src\lib.rs:22:15:
длина исходного фрагмента (400212022800) не соответствовать длине фрагмента назначения (32)"
не уверен, что я здесь делаю не так.
любая помощь поможет.
спасибо.
Подробнее здесь: https://stackoverflow.com/questions/791 ... using-cdll