function ApplyPKCS5Padding (v_to_pad raw)
return raw
IS
a_var VARCHAR2 (100);
num_padding_bytes Int;
padding_bytes raw(100);
test_byte raw(1);
zero_byte raw(1);
output raw(2000);
BEGIN
-- Since DES needs data to be in multples of 8 bytes we pad the data, if the
-- data did not meet the 8 bytes boundry requirment.
num_padding_bytes := MOD(Length(utl_raw.cast_to_varchar2(v_to_pad)),8);
output := v_to_pad;
IF (num_padding_bytes) != 0 THEN
padding_bytes := '';
zero_byte := '0';
test_byte := utl_raw.cast_to_raw(8-num_padding_bytes);
test_byte := utl_raw.bit_and(test_byte, '0F');
for lcntr in 1..8-num_padding_bytes
loop
padding_bytes := UTL_RAW.CONCAT(padding_bytes, test_byte);
end loop;
output := utl_raw.concat(v_to_pad, padding_bytes);
ELSE
padding_bytes := '0808080808080808';
output := utl_raw.concat(v_to_pad, padding_bytes);
END IF;
return output;
END;
The default IV is... I have no idea, but the OBFS toolkit and DBMS_CRYPTO have a different one. I just had to specify it, I did the testing with a 0 IV. Also, the default for OBFS is 2-key 3des, so I needed the which => 1
to change it to 3key. Thanks for the help!
EDIT: The original "solution" actually failed on Strings with length%8 == 0, due to a misinterpretation of the PKCS#7/5 spec... I've update the solution above to show the entire/functioning code.