I have a client that needs to send an encrypted/encoded string of data to vendor to gain access to an web application. I'm using RPG to accomplish this and everything is working fine but my encrypted/encoded string is not being accepted by my client's vendor. I'm using the QC3ENCDT encryption API and Scott's Klement's BASE64 encoding program and it's not giving me what the vendor's needs to see. I'm not real sure I have all the parameters set correctly on the QC3ENCDT to match the JAVA sample provided below. The vendor has supplied the JAVA code snippet to handle the encryption/encoding, but not being a JAVA programmer, I don't know if I create this code on the ISeries as I know nothing about JAVA. The vendor is having concerns if the AS400 can accomplish this and I know it can if the programmer was somewhat smarter. If anyone could help create this on the AS400 so that I call it from an RPG program or help in configuring the QC3ENCDT API, I would be willing to pay for your time. My clinet's OS version is V5R3.
Below is the JAVA code snippet provided by the vendor...
Thanks!
Below is the JAVA code snippet provided by the vendor...
Code:
public String encrypt(String cleartext, String key, String alg) { String encrpytedString = null; byte[] ciphertext = null; try { byte[] raw = new BASE64Decoder().decodeBuffer(key); SecretKeySpec skeySpec = new SecretKeySpec(raw, alg); //use some padding parameters to avoid Bad Padding exception Cipher desCipher = Cipher.getInstance(alg + "/ECB/PKCS5Padding"); desCipher.init(Cipher.ENCRYPT_MODE, skeySpec); ciphertext = desCipher.doFinal(cleartext.getBytes("UTF8")); //do not convert byte[] to String directly. user BASE64 instead. //A base64 encoded byte array only contains displayable characters. //The returned byte array may contain control characters //or other characters that should not be present in a string encrpytedString = new sun.misc.BASE64Encoder().encode (ciphertext); } catch (Exception e) { e.printStackTrace(System.out); } return encrpytedString; }
Comment