
dbaccess sysmaster

drop database justdave;
create database justdave in datadbs;

create table a 
(
  client_id int,
  client_name char(30)
)

# encrypt_aes(data,password,hint)

insert into a values(1,'JERRY');
insert into a values(2,ENCRYPT_AES('WHO?','pass1','hintdave'));
insert into a values(2,ENCRYPT_AES('WHO?','justdave1','hintdave'));

select * from a;
select client_id,DECRYPT_CHAR(client_name,'justdave1') from a where client_id=2;

drop table a;
create table a 
(
  client_id int,
  client_name char(100)
);

insert into a values(1,'JERRY');
insert into a values(2,ENCRYPT_AES('WHO?','justdave1','hintdave'));

select client_id,client_name,length(client_name) len from a;

select * from a;
select client_id,DECRYPT_CHAR(client_name,'justdave1') from a where client_id=1;
select * from a; 
select client_id,DECRYPT_CHAR(client_name,'justdave1') from a where client_id=2;

# encrypt_tdes(data,password,hint)
insert into a values(3,ENCRYPT_TDES('JERRY!!','justdave1'));
select client_id,DECRYPT_CHAR(client_name,'justdave1') from a where client_id=3;

SET ENCRYPTION PASSWORD "justdave1";
select client_id,DECRYPT_CHAR(client_name) from a order by client_id;

select client_id,client_name from a where client_id=1
union
select client_id,DECRYPT_CHAR(client_name) from a where client_id > 1;

# Blobs
rm -f /tmp/a1 /tmp/b1 /tmp/a2.* /tmp/b2.* /tmp/a3.* /tmp/b3.*
echo "HIDDEN TEXT A" > /tmp/a1
echo "HIDDEN TEXT B" > /tmp/b1

dbaccess justdave
create table b
(
client_id int,
decrypt_filename varchar(100),
client_file blob
);

insert into b values(4,'/tmp/a3',ENCRYPT_AES(FILETOBLOB('/tmp/a1','server'),'justdave2'));
insert into b values(5,'/tmp/b3',ENCRYPT_TDES(FILETOBLOB('/tmp/b1','server'),'justdave2'));

select client_id,LOTOFILE(DECRYPT_BINARY(client_file,'justdave2'),'/tmp/a2','server') from b where client_id=4;
more /tmp/a2.* /dev/null
select client_id,LOTOFILE(DECRYPT_BINARY(client_file,'justdave2'),'/tmp/b2','server') from b where client_id=5;
more /tmp/b2.* /dev/null

SET ENCRYPTION PASSWORD "justdave2";
select client_id,LOTOFILE(DECRYPT_BINARY(client_file,'justdave2'),decrypt_filename,'server') from b order by client_id;
more /tmp/[ab]3.*

oncheck -pe  | egrep "Description|justdave.*root"
dd if=/opt/IDS.12.10.FC5/storage/datadbs ibs=2048 skip=1792 count=1 | strings # +1 on skip

ontape -s -L 0 -t STDIO > /dev/null
update a set client_name='HARRY' where client_id=1;
onmode -c
update a set client_name='Mike is here' where client_id=1;

ontape -s -L 1 -t STDIO > /tmp/2 # changed pages
strings /tmp/2 | grep 'Mike is here'

create index c1 on a(client_name);

# 0x00400044
select hex(b.partn) from systables a,sysfragments b where b.indexname='c1' and a.tabid=b.tabid and a.tabname='a';

oncheck -pp 0x00400044 1 # Encrypted!

create function my_upper( s varchar(100) ) returning varchar(100) with
(not variant) ;
  return upper(s) ;
end function;
create index c2 on a(my_upper(client_name));
select hex(b.partn) from systables a,sysfragments b where b.indexname='c2' and a.tabid=b.tabid and a.tabname='a';


