我正在尝试使用QCA来加密/解密文件 当我使用此代码进行加密时,一切正常(或者似乎至少) 但是当我尝试解密时,process()方法返回一个空的SecureArray 有没有人知道为什么和/或如何解决它?
void FileCrypto::crypt(QByteArray key, bool crypt){
QCA::Initializer init;
open();
Cipher cipher = initializeCipher(key, crypt);
QTextStream in(source); //lecture ligne par ligne
while (!in.atEnd()) {
QString line = in.readLine();
SecureArray secureData = line.toAscii().data(); //securise les donnees
if(!crypt)
QString temp = QString::fromAscii(secureData.toByteArray().toHex());
qDebug() << "Données lues : " << secureData.data();
SecureArray cryptedData = cipher.process(secureData); //(de)crypte les donnees
qDebug() << "Données cryptées :" << cryptedData.data();
destination->write(cryptedData.data()); //ecris dans le nouveau fichier
}
close();
}
void FileCrypto::open() throw (QString){
if(!source->open(QIODevice::ReadOnly | QIODevice::Text)
|| !destination->open(QIODevice::WriteOnly | QIODevice::Text)){
throw QString("Impossible d'ouvrir les fichiers cibles.");
}
}
void FileCrypto::close(){
source->close();
destination->close();
}
Cipher FileCrypto::initializeCipher(QByteArray akey, bool crypt){
QCA::InitializationVector iv;
Direction direction;
SymmetricKey key = SymmetricKey(akey);
iv = InitializationVector(akey);
if(crypt){
direction = Encode;
}else{
direction = Decode;
}
return Cipher(QString("blowfish"),Cipher::CBC,
Cipher::DefaultPadding, direction, key, iv);
}