• Dimitri D
  • NEWBIE
  • 0 Points
  • Member since 2010
  • 4C Consulting

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 6
    Replies

Hi everybody

 

For a customer, I should decrypt a userid received crypted from a java class.

 

I have made different tests in order to try to encrypt the same string and compare both values (before trying to decode the recevied string) but unsuccessfully until now.

 

The java class is the following (I am not a java specialist) :

 

 

byte[] keyBytes = keyText.getBytes(); 
                
      // Instantiate the key (base on the keybytes and the encryption algorithm) 
SecretKeySpec skeySpec = new SecretKeySpec(keyBytes, "AES");
                  
      // Instantiate the cipher
      Cipher cipher;
      
      // AES/CBC/PKCS5Padding is used to keep compatibility with other languages platform 
      cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
      
      // Instantiate the Initialisation vector ( only based on the keybytes)  
      IvParameterSpec ivParameterSpec = new IvParameterSpec(keyBytes);
                  
      cipher.init(Cipher.ENCRYPT_MODE, skeySpec, ivParameterSpec);
                  
      encrypted = cipher.doFinal(   (userId).getBytes());
                                    
      BASE64Encoder _64e = new BASE64Encoder();
            
      String sEncode = _64e.encode(encrypted);
            
      // due to problem with "+;/" the value encoded in base64 is encoded into a URL encoding
      result = URLEncoder.encode(sEncode, "UTF-8");

 

 

The AEPX code used is the following :

 

 

trigger Decrypt on Account (before update) {

	for (Account ac : trigger.new) {
		ac.Name = ac.Name.substring(0,4) + ' - ' + system.now().hour() + ':' + system.now().minute() + ':' + system.now().second();

		// Generate the data to be encrypted.
		Blob data = Blob.valueOf('EAF099');
		
		// Key Definition
		Blob myBlobKey	= Blob.valueof('xxxyyyzzz'); // replaced with true value
		
		// Encrypt the data and have Salesforce.com generate the initialization vector 
		Blob encryptedData = Crypto.encryptWithManagedIV('AES128', myBlobKey, data);
		// Update Description on Account
		ac.Description = ac.Description + ' - - - encryptedData.toString() : ' + encryptedData.toString();
		ac.Description = ac.Description + ' - - - EncodingUtil.base64Encode(encryptedData) : ' + EncodingUtil.base64Encode(encryptedData);
		
		// Decrypt the data
		Blob decryptedData = Crypto.decryptWithManagedIV('AES128', myBlobKey, encryptedData);
		// Update Description on Account
		ac.Description = ac.Description + '___ decryptedData.toString() : ' + decryptedData.toString();

	}

}

 

 

Has anyone more experience with crypto class ?? Is this possible ??

 

Thanks in advance

 

Dimitri

Hello

 

Everytime I use a single trigger in order to encrypt/decrypt a value, I receive a different crypted data. If I don't change my value, normally, the encrypted data should be the same ?

 

My code (just a test at the moment being) :

 

 

trigger Decrypt on Account (before update) {

	for (Account ac : trigger.new) {

		// Generate the data to be encrypted.
		Blob data = Blob.valueOf('EAF098');
		
		// Key Definition
		string myKey	= 'XXXXXXXXX'; // Real value replaced with X
		Blob myBlobKey	= Blob.valueof(myKey);
		
		// Encrypt the data and have Salesforce.com generate the initialization vector 
		Blob encryptedData = Crypto.encryptWithManagedIV('AES128', myBlobKey, data);
		// Update Description on Account
		ac.Description = ac.Description + ' - - - ' + encryptedData.toString();
		ac.Description = ac.Description + ' - - - ' + EncodingUtil.base64Encode(encryptedData);
		
		// Decrypt the data
		Blob decryptedData = Crypto.decryptWithManagedIV('AES128', myBlobKey, encryptedData);
		// Update Description on Account
		ac.Description = ac.Description + '___' + decryptedData.toString();

	}
}

 

 

Anyone has an idea ??

 

Thanks

 

Dimitri

Hi

 

I have successfully imported the Entreprise WSDL into a new SOAP Project. I can LOGIN with success, use the GETSERVERTIMESTAMP successfully but I am unable to use the UPSERT call.

 

I have copy-pasted part of the sample available here : SOAP Sample Message

 

 

<urn:externalIDFieldName>CIEID__C</urn:externalIDFieldName>
   <urn:sObjects xsi:type="Account">
      <CIEID__C>1330</CIEID__Cc>
      <Name>Acme Rocket Superstore</Name
      <NumberOfEmployees>340</NumberOfEmployees>
   </urn:sObjects>

 Error msg : The prefix "xsi" for attribute "xsi:type" associated with an element type "urn:sObjects" is not bound.

 

 

So, code was adapted :(xsi:type was removed) :

 

   <urn:sObjects ="Account">
      <CIEID__C>1330</CIEID__Cc>
      <Name>Acme Rocket Superstore</Name>
      <NumberOfEmployees>340</NumberOfEmployees>
   </urn:sObjects>

 

Error msg : Element type "urn:sObjects" must be followed by either attribute specifications, ">" or "/>". (I also tried with <urn:sObjects =Account> with the same error msg).

 

Finally, code was adapted to :

 

 

   <urn:sObjects>Account</urn:sObjects>
      <CIEID__C>1330</CIEID__Cc>
      <Name>Acme Rocket Superstore</Name>
      <NumberOfEmployees>340</NumberOfEmployees>
   <!--/urn:sObjects-->

 And error msg was : INVALID_TYPE: Must send a concrete entity type

 

Do someone have any idea how to successfully make such a call ??

 

Thank you in advance

 

Dimitri

 

Hello

 

I'm trying to create a Web Service and it's test class in order to upsert Accounts from another system.

 

I'm encoutering a problem when trying to generate exception : my test class will fail and complete with errors :

 

Here is my Web Service Class :

 

global class ReceiveAccountWS {

// Receive Account Web Service
// Receives an Account and upsert it based on External ID : CIEID__c

webService static Id UpdateAccount(String extID, Account acc) {

Account a = new Account();
system.debug('*** Debug acc: ' + acc);
a = acc;
system.debug('*** Debug a : ' + a);
a.CIEID__c = '' + extID;
try {
upsert a CIEID__c;
system.debug('*** Debug upsert OK : ' + a);
return a.id;
} catch (StringException s) {
System.debug('*** Debug Error String : ' + s.getMessage());
string Ers = s.getMessage();
throw s;
return Ers;
} catch (DmlException d) {
System.debug('*** Debug Error DML : ' + d.getMessage());
string Erd = d.getMessage();
return Erd;
} catch (Exception e) {
System.debug('*** Debug Error Exception: ' + e.getMessage());
string Ere = e.getMessage();
return Ere;
}
}
}

 

And here is my Test Class : for acc2, the Account name is intentionaly left blank :

 

public class Z_TestReceiveAccountWS {

static testMethod void TestReceiveAccountWS() {
Account acc = new Account();
Account acc2 = new Account();
acc.Name = 'TEST Account';
String MyID = '007';
String MyID2 = '008';

ReceiveAccountWS.UpdateAccount(MyID, acc);
ReceiveAccountWS.UpdateAccount(MyID2, acc2);
}
}

 

The test result is the following :

 

Test ClassZ_TestReceiveAccountWS
Tests Run1
Test Failures1
Code Coverage Total %72
Total Time (ms)106.0

 

 

System.StringException: Invalid id: Upsert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Name]: [Name]

Class.ReceiveAccountWS: line 8, column 23 Class.Z_TestReceiveAccountWS.TestReceiveAccountWS: line 11, column 3 External entry point

 

How may I avoid to receive such an exception that I thought I had catched ??

 

Any help is appreciated.

 

Thank you

 

Dimitri

Hello

 

Everything is running fine in Prod (hopefully), the problem is in Sandbox.

 

We have developped a synch between SalesForce and another (ERP) system. Things are running fine untill now.

 

The cutomer has created a Sandbox in order to test the synch due to a major release of the external system.

 

He has adapted the Remote Site in Configuration and the new URL - Login & Password in a custom object.

 

However, we are still receiving an error message : handshake_failure.

 

Is it possible that this is due to the fact that both top level URL's in Remote Site, in Prod & in Sandbox are the same : https://mail.mycustomer.be:7000 for Prod & https://mail.mycustomer.be:7005 for Sandbox ??

 

By using another system (VBA), with the given Sandbox URL, login & password : I receive a correct answer from external system => these are corrects.

 

Anyone any idea ??

 

Thanks

Hi

 

I have successfully imported the Entreprise WSDL into a new SOAP Project. I can LOGIN with success, use the GETSERVERTIMESTAMP successfully but I am unable to use the UPSERT call.

 

I have copy-pasted part of the sample available here : SOAP Sample Message

 

 

<urn:externalIDFieldName>CIEID__C</urn:externalIDFieldName>
   <urn:sObjects xsi:type="Account">
      <CIEID__C>1330</CIEID__Cc>
      <Name>Acme Rocket Superstore</Name
      <NumberOfEmployees>340</NumberOfEmployees>
   </urn:sObjects>

 Error msg : The prefix "xsi" for attribute "xsi:type" associated with an element type "urn:sObjects" is not bound.

 

 

So, code was adapted :(xsi:type was removed) :

 

   <urn:sObjects ="Account">
      <CIEID__C>1330</CIEID__Cc>
      <Name>Acme Rocket Superstore</Name>
      <NumberOfEmployees>340</NumberOfEmployees>
   </urn:sObjects>

 

Error msg : Element type "urn:sObjects" must be followed by either attribute specifications, ">" or "/>". (I also tried with <urn:sObjects =Account> with the same error msg).

 

Finally, code was adapted to :

 

 

   <urn:sObjects>Account</urn:sObjects>
      <CIEID__C>1330</CIEID__Cc>
      <Name>Acme Rocket Superstore</Name>
      <NumberOfEmployees>340</NumberOfEmployees>
   <!--/urn:sObjects-->

 And error msg was : INVALID_TYPE: Must send a concrete entity type

 

Do someone have any idea how to successfully make such a call ??

 

Thank you in advance

 

Dimitri

 

Hello

 

I'm trying to create a Web Service and it's test class in order to upsert Accounts from another system.

 

I'm encoutering a problem when trying to generate exception : my test class will fail and complete with errors :

 

Here is my Web Service Class :

 

global class ReceiveAccountWS {

// Receive Account Web Service
// Receives an Account and upsert it based on External ID : CIEID__c

webService static Id UpdateAccount(String extID, Account acc) {

Account a = new Account();
system.debug('*** Debug acc: ' + acc);
a = acc;
system.debug('*** Debug a : ' + a);
a.CIEID__c = '' + extID;
try {
upsert a CIEID__c;
system.debug('*** Debug upsert OK : ' + a);
return a.id;
} catch (StringException s) {
System.debug('*** Debug Error String : ' + s.getMessage());
string Ers = s.getMessage();
throw s;
return Ers;
} catch (DmlException d) {
System.debug('*** Debug Error DML : ' + d.getMessage());
string Erd = d.getMessage();
return Erd;
} catch (Exception e) {
System.debug('*** Debug Error Exception: ' + e.getMessage());
string Ere = e.getMessage();
return Ere;
}
}
}

 

And here is my Test Class : for acc2, the Account name is intentionaly left blank :

 

public class Z_TestReceiveAccountWS {

static testMethod void TestReceiveAccountWS() {
Account acc = new Account();
Account acc2 = new Account();
acc.Name = 'TEST Account';
String MyID = '007';
String MyID2 = '008';

ReceiveAccountWS.UpdateAccount(MyID, acc);
ReceiveAccountWS.UpdateAccount(MyID2, acc2);
}
}

 

The test result is the following :

 

Test ClassZ_TestReceiveAccountWS
Tests Run1
Test Failures1
Code Coverage Total %72
Total Time (ms)106.0

 

 

System.StringException: Invalid id: Upsert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Name]: [Name]

Class.ReceiveAccountWS: line 8, column 23 Class.Z_TestReceiveAccountWS.TestReceiveAccountWS: line 11, column 3 External entry point

 

How may I avoid to receive such an exception that I thought I had catched ??

 

Any help is appreciated.

 

Thank you

 

Dimitri