Pessoal estamos integrando nosso autorizador ao SITEF o problema está em descriptografar o PINBLOCK conforme documentação abaixo:
Ao aplicar a descriptografia 3-DES sobre o PINBlock “fechado”, obtém-se o PINBlock “aberto”.
A descriptografia 3-DES é feita com as seguintes observações:
Descriptografa – Criptografa – Descriptografa – o PINBlock fechado é submetido a:
1 - Descriptografia DES com a primeira componente da Working Key Aberta; a partir do resultado, aplica-se:
2 - Criptografia DES com a segunda componente da Working Key Aberta; a partir do resultado, aplica-se:
3 - Descriptografia DES com a terceira componente da Working Key Aberta.
Encadeamento Electronic Codebook (ECB) – na prática não ocorre encadeamento, pois o tamanho do PINBlock é 8 bytes (64 bits), mesmo tamanho de um bloco de dados 3-DES. O Initialization Vector (IV) não faz sentido, pois não é usado no encadeamento ECB. Porém se a biblioteca exigir, preenchê-lo com zeros binários.
Preenchimento do último bloco (Padding) – não ocorre padding pois, conforme dito anteriormente, o tamanho do PINBlock é o mesmo de um bloco de dados 3-DES. Porém se a biblioteca exigir, utilizar a opção “nenhum”.
Os detalhes e exemplo do que tenho que fazer estão na página 12 do manual abaixo:
Manual
tentei fazer o item 1 com o método DecryptCipherTextToPlainText do método abaixo
(https://dotnetfiddle.net/SvJiXF)
public static string DecryptCipherTextToPlainText(string textoCriptografado)
{
byte[] toEncryptArray = Convert.FromBase64String(textoCriptografado);
MD5CryptoServiceProvider objMD5CryptoService = new MD5CryptoServiceProvider();
//Gettting the bytes from the Security Key and Passing it to compute the Corresponding Hash Value.
byte[] securityKeyArray = objMD5CryptoService.ComputeHash(UTF8Encoding.UTF8.GetBytes(_securityKey));
//De-allocatinng the memory after doing the Job.
objMD5CryptoService.Clear();
var objTripleDESCryptoService = new TripleDESCryptoServiceProvider();
//Assigning the Security key to the TripleDES Service Provider.
objTripleDESCryptoService.Key = securityKeyArray;
//Mode of the Crypto service is Electronic Code Book.
objTripleDESCryptoService.Mode = CipherMode.ECB;
//Padding Mode is PKCS7 if there is any extra byte is added.
objTripleDESCryptoService.Padding = PaddingMode.None;
byte[] DataToDecrypt = Convert.FromBase64String(textoCriptografado);
var objCrytpoTransform = objTripleDESCryptoService.CreateDecryptor();
//Transform the bytes array to resultArray
byte[] resultArray = objCrytpoTransform.TransformFinalBlock(DataToDecrypt, 0, DataToDecrypt.Length);
//Releasing the Memory Occupied by TripleDES Service Provider for Decryption.
objTripleDESCryptoService.Clear();
//Convert and return the decrypted data/byte into string format.
return UTF8Encoding.UTF8.GetString(resultArray);
}`
não deu certo sempre retorna o seguinte erro:
[System.Security.Cryptography.CryptographicException: Length of the data to decrypt is invalid.]
at Program.DecryptCipherTextToPlainText(String textoCriptografado): line 46
at Program.Main(): line 12
alguém tem experiência com isso? preciso de um help um tanto quanto urgente. Desde já obrigado galera…