#coding:utf-8 """ ID: issue-6858 ISSUE: 6858 TITLE: RSA_DECRYPT() can not decrypt data if it relates to BLOB type DESCRIPTION: FBTEST: bugs.gh_6858 """ import pytest from firebird.qa import * db = db_factory() test_script = """ recreate table test( id int generated by default as identity constraint pk_txt primary key ,blb blob character set utf8 --,blb varchar(1) character set utf8 ); insert into test(blb) values('A'); commit; -- NO errors must be issued during following EB execution: -- ############## -- Previous error messages see in commented lines below: set term ^; execute block as declare k_prv varbinary(16384); declare k_pub varbinary(8192); declare blob_encrypted blob character set octets; declare vchr_encrypted varchar(256) character set octets; declare blob_decrypted blob character set utf8; declare vchr_decrypted varchar(10) character set utf8; begin k_prv = rsa_private(256); k_pub = rsa_public(k_prv); for select id, blb from test as cursor c do begin blob_encrypted = rsa_encrypt(c.blb key k_pub hash md5); vchr_encrypted = rsa_encrypt(c.blb key k_pub hash md5); --------------------------### 1 ###------------------------------- -- SQLSTATE = 22023 / TomCrypt library error: Invalid input packet. / -Decrypting using cipher RSA blob_decrypted = rsa_decrypt(blob_encrypted key k_prv hash md5); --------------------------### 2 ###------------------------------------------ -- if declared length of `vchr_decrypted` is 256 then: -- SQLSTATE = 22023 / TomCrypt library error: Invalid input packet. / -Decrypting using cipher RSA -- if declared length of `vchr_decrypted` is 10, then OK: vchr_decrypted = rsa_decrypt(blob_encrypted key k_prv hash md5); --------------------------### 3 ###------------------------------- -- malformed string blob_decrypted = rsa_decrypt(vchr_encrypted key k_prv hash md5); --------------------------### 4 ###------------------------------- -- malformed string vchr_decrypted = rsa_decrypt(vchr_encrypted key k_prv hash md5); end end ^ set term ;^ """ act = isql_act('db', test_script) @pytest.mark.version('>=4.0') def test_1(act: Action): act.execute() assert act.clean_stdout == act.clean_expected_stdout