Kinetic Text Encryption

Dear Expert,
May I know is there any solution to convert my current classic code on Encryptor

My last previous code which can work fine in E10.2.400.34 but but looks like is not working anymore in Kinetic 2023.2, and anyone here advice me how to change or any way to work around this?

		using (SqlConnection Connection1 = new SqlConnection(GetSQLConn())) 
		{
			Connection1.Open();
			SqlCommand SPCmd = new SqlCommand(
			" SELECT SMTPServer, SMTPPort, SMTPAcct, SMPTAcctPW, SMTPEnableSSL " + 
			" FROM Ice.SysCompany " +
			" WHERE Company = @Company", Connection1);
			SPCmd.CommandType = CommandType.Text;
			SPCmd.Parameters.Add("Company", SqlDbType.NVarChar).Value = ((Ice.Core.Session)(oTrans.Session)).CompanyID;
			SqlDataReader reader = SPCmd.ExecuteReader();
			while (reader.Read()) 
			{
				if (reader[0] != DBNull.Value)
				{
					xSMTPServer = Convert.ToString((string)reader[0]);
					xSMTPPort = Convert.ToInt32((int)reader[1]);
					xSMTPAcct = Convert.ToString((string)reader[2]);
					xSMTPAcctPW = Epicor.Security.Cryptography.Encryptor.DecryptToString(Convert.ToString((string)reader[3]));
					xSMTPEnableSSL = Convert.ToBoolean((bool)reader[4]);
				}
			}
			Connection1.Close();
			Connection1.Dispose();
		}

This is for me to pull out the setup SMTP info on Order entry to send an email for approval purpose, I has write a middle ware to received the approved email to authorize the order.

But seem like the Encryptor does not work anymore please assist thanks.

They changed the way it works.

Thanks @klincecum
but sorry for me still fresh in kinetic, and what is the key come from? looks like I need a key value to open it and where is this key value come from?
the old code we just straight pass in the encrypted code but now looks like we need more?

Yes. I just made my key and stuff up, but I’m sure there’s a more elegant way to use it. Just pushing you in the right direction.

2 Likes

hi @klincecum, sorry for late on this.
i hit following error after i trying to use your sample code to decrypt the value.

Application Error

Exception caught in: mscorlib

Error Detail

Message: Exception has been thrown by the target of an invocation.
Inner Exception Message: Padding is invalid and cannot be removed.
Program: CommonLanguageRuntimeLibrary
Method: InvokeMethod

actually what is this?

Your data has to be the right size for the cipher being used.