You do not need to actually implement PBEWithMD5andDES, assuming ruby has a DES implementation. What you need to implement is the key derivation function (who you get the key from the password), and then pass this derived key to DES with the appropriate mode and addition.
Fortunately, the key derivation function is not particularly important for security during implementation, so you can do it yourself safely enough. According to rfc , PBEwithMD5AndDES is actually PBKDF1 (kera output function) used with DES in CBC mode.
PBKDF1 doesn't look so hard to implement. It looks like you can do this with a for loop and calling md5.
Note that you can still get some odd results due to the possibility of using a different padding scheme in Java and Ruby. I assume spec one is a complement to pkcs 1.5, but with a quick glance I cannot confirm this.
5.1 PBKDF1
PBKDF1 applies the hash function, which must be MD2 [6], MD5 [19] or SHA-1 [18] in order to receive the keys. Derived Key Length Limited
the hash function output length, which is 16 octets for MD2 and MD5 and 20 octets for SHA-1. PBKDF1 is a key-compatible derivation process in PKCS No. 5 v1.5.
PBKDF1 is recommended only for compatibility with existing
applications because the keys it produces may not be large enough for
some applications.
PBKDF1 (P, S, c, dkLen)
Parameters: Hash hash function
Input: password P, octet string S salt, eight-octave thread c iteration, positive integer dkLen expected length in octets of the derived key, positive integer, not more than 16 for MD2 or MD5 and 20 for SHA-1
Conclusion: the key generated by DK, dkLen octet string
Steps:
1. If dkLen > 16 for MD2 and MD5, or dkLen > 20 for SHA-1, output "derived key too long" and stop. 2. Apply the underlying hash function Hash for c iterations to the concatenation of the password P and the salt S, then extract the first dkLen octets to produce a derived key DK: T_1 = Hash (P || S) , T_2 = Hash (T_1) , ... T_c = Hash (T_{c-1}) , DK = Tc<0..dkLen-1> 3. Output the derived key DK.