function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
henryCHhenryCH 

XOR encryption for encrypted authentication

Hi,

 

We tried to implement a single sign on mechanism of a third party web solution using the Crypto.encrypt method. The third party solution requires that the initialization vector is XOR encoded into the first 16 bytes of the transmitted SSO Token. In java this would be done like this:

 

 

for (int i = 0; i < 16; i++) {
   data[i] ^= INIT_VECTOR[i];
}

 

 

where data and INIT_VECTOR would be byte arrays. In Apex there's nothing like a byte array and Blob has no methods at all. The XOR operator ^ does exist in Apex but it can only be used with Boolean expressions and Integers. So I can't just use the Strings and do some wild XOR character operations. Does anybody know how I can implement an XOR encryption like in Java or any other programming language using Apex?

 

Thanks for your help and best regards,

Henry

Best Answer chosen by Admin (Salesforce Developers) 
henryCHhenryCH

Hi,

 

I found a solution myself, so just in case somebody else has the same strange problem, just let me know and I'll send you the code.

 

Best regards,

Henry

All Answers

henryCHhenryCH

Hi,

 

I found a solution myself, so just in case somebody else has the same strange problem, just let me know and I'll send you the code.

 

Best regards,

Henry

This was selected as the best answer
pohkagmpohkagm

Hi Henry,

 

I hope you are still out there.  I too have to salt my blob with the same expression ... how did you do it?  I am attempting a SSO onto UserVoice.

 

Your help will be greatly appreciated.

 

Thanks

 

keith

kprkpr

Hi Henry,Keith,


Can you let me know how you solved this? I have a similar issue where I want to extract bytes from the data and process them.

 

Thanks,

kpr

SidhuSidhu

Hello Henry, 

 

I am trying to do a Single Sign On implementation to Desk.com. They do a multipass authentication mechanism and I need to do exactly what you decribed above. Can you guide me on how you solved this probelm? 

 

Thank you, 

Sidhu

VVKrishnaVVKrishna

Hi Henry,

 

Can you please send me the code for XOR.  I have a requirement to XOR the keys before encrypting the data.  Appreciate your help.

 

Regards,

Vamshee.