在Rails中加密和在Salesforce中解密

时间:2019-01-25 04:05:34

标签: ruby-on-rails encryption salesforce

我正在Rails项目中使用attr_encrypted gem,并在PostgreSQL数据库中加密银行帐号。在数据库中,我有两列(encrypted_bank_account和encrypted_bank_account_iv)用于加密数据。我的payment_method模型文件中包含以下行:

attr_encrypted :account_number, key: ENV['ACCOUNT_KEY'], encode: true, encode_iv: true, algorithm: 'aes-256-cbc'

我希望能够将此加密数据发送到SalesForce,对其进行解密,然后将其存储在SalesForce对象中。我不确定如何在到达目的地时如何解密它,并可以使用一些建议。谢谢!

1 个答案:

答案 0 :(得分:1)

在Salesforce上具有一个端点,该端点可以获取数据并在

中对其进行解密
// Normally this key should be stored in a protected custom setting 
// or an encrypted field on a custom object
Blob cryptoKey = Crypto.generateAesKey(256);

// Generate the data to be encrypted.
Blob data = Blob.valueOf('Test data to encrypted');
// Encrypt the data and have Salesforce.com generate the initialization vector
Blob encryptedData = Crypto.encryptWithManagedIV('AES256', cryptoKey, data);
// Decrypt the data - the first 16 bytes contain the initialization vector
Blob decryptedData = Crypto.decryptWithManagedIV('AES256', cryptoKey, encryptedData);

// Decode the decrypted data for subsequent use
String decryptedDataString = decryptedData.toString();


https://developer.salesforce.com/page/Apex_Crypto_Class