class Program

    {

        static void Main(string[] args)

        {

            //Partner Account

            string allianceId = "12345";

            string sid = "987654";


            //Partner password, will be received from Ctrip

            string userKey = "af85s54f66s4fd5s64f112sf25";

            //Unique signature, will be received from Ctrip

            string icode = "95fs2sf123s1f23s1f56s4f1s3f";

            //Guid, generated by parter and need to be unique in each request.

            string uuid = Guid.NewGuid().ToString().Replace("-", "");

            string[] p = new string[] { allianceId, sid, userKey, icode, uuid };

            string data = string.Format("aid={0}&sid={1}&userkey={2}&icode={3}&uuid={4}", p);

            string encryptData = SHA256(data);

            System.Console.WriteLine(String.Format("orginal:{0}", data));

            System.Console.WriteLine(String.Format("encrypted:{0}", encryptData));

            System.Console.ReadLine();

        }


        #region  SHA256 encryption algorithm



        /// <summary>

        /// SHA256 function

        /// </summary>

        /// <param name="str">default string</param>

        /// <returns>SHA256 result(returning 44 bytes string)</returns>

        public static string SHA256(string str)

        {

            byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(str);

            try

            {

                SHA256 sha256 = new SHA256CryptoServiceProvider();

                byte[] retVal = sha256.ComputeHash(bytValue);

                StringBuilder sb = new StringBuilder();

                for (int i = 0; i < retVal.Length; i++)

                {

                    sb.Append(retVal[i].ToString("x2"));

                }

                return sb.ToString();

            }

            catch (Exception ex)

            {

                throw new Exception("GetSHA256HashFromString() fail,error:" + ex.Message);

            } 

        }

        #endregion

    }

                

    import java.io.UnsupportedEncodingException;

    import java.security.MessageDigest;

    import java.security.NoSuchAlgorithmException;

    import java.util.UUID;

        

    public class Test {

        public static void main(String[] args){

           //Partner Account

           String allianceId = "12345";

           String sid = "987654";

           //Partner password, will be received from Ctrip

           String userKey = "af85s54f66s4fd5s64f112sf25";

           //Unique signature, will be received from Ctrip

           String icode = "5fd08a3e30c14fd49c5f4b11a6094b83";

           //Guid, generated by parter and need to be unique in each request.

           String uuid = UUID.randomUUID().toString().replaceAll("\\-", "");

           String[] p = new String[] { allianceId, sid, userKey, icode, uuid };

           String data = String.format("aid=%s&sid=%s&userkey=%s&icode=%s&uuid=%s", p);

           String encryptData = getSHA256StrJava(data);

           System.out.println(String.format("orginal:%s", data));

           System.out.println(String.format("encrypted:%s", encryptData));

        }

       

        public static String getSHA256StrJava(String str){

           MessageDigest messageDigest;

           String encodeStr = "";

           try {

               messageDigest = MessageDigest.getInstance("SHA-256");

               messageDigest.update(str.getBytes("UTF-8"));

               encodeStr = byte2Hex(messageDigest.digest());

           } catch (NoSuchAlgorithmException e) {

               return null;

               //e.printStackTrace();

           } catch (UnsupportedEncodingException e) {

               return null;

               //e.printStackTrace();

           }

               return encodeStr;

        }

             

         private static String byte2Hex(byte[] bytes){

            StringBuffer stringBuffer = new StringBuffer();

            String temp = null;

            for (int i=0;i < bytes.length;i++)

            {

               temp=Integer.toHexString(bytes[i]& 0xff );

               if (temp.length()= =1){

                  stringBuffer.append("0");

               }

               stringBuffer.append(temp);

            }

            return stringBuffer.toString();

        }

    }