EncodeStr = URLEncoding(Base64(Encrypt(SpNumber + “$”+ UserNumber + “$”+ ServiceTag + “$”+ AccessTime )))
URLEncoding是指对BASE64编码中的HTML控制码进行转义的过程,其具体实现参见RFC1738。
Encrypt加密算法采用3-DES算法,密钥为64位。
调用示例:
http://www.unispms.com/subscription/servicepull.aspx?SPNumber=30165&AccessTime=2004-01-01 10:10:10&EncodeStr=KIQWNWEQREQWK921343KJ
 HTTP点播调用返回参数
SP调用HTTP点播接口后,返回调用结果。
A. 处理成功:返回“OK”。
B. 处理失败:返回“Error$” + 错误码。问题现在我呀在  C#。NET 里写。    在C#里那位高手写过。

解决方案 »

  1.   

    http://tb.blog.csdn.net/TrackBack.aspx?PostId=276322
      

  2.   

    帮我把加密部分写出来就好  下面这个。  改成C#的就可以了。 因为下面的是JAVA写的。EncodeStr = URLEncoding(Base64(Encrypt(SpNumber + “$”+ UserNumber + “$”+ ServiceTag + “$”+ AccessTime )))
      

  3.   

    Encrypt函数就是加密部分,给你个加密类这个我在项目开发中写的TripleDES加密类,可以加密字符串,也可以加密字节数组。你只需要把Encrypt函数替换成我的加密类中加密字符串的方法既可。
    /*************************************************************************
     *  Copyright(C) 2004-2005 ******** All Rights Reserved.
     ************************************************************************/using System;
    using System.IO;
    using System.Text;
    using System.Security.Cryptography;
    using System.Web;
    using System.Windows.Forms;
    /// <summary>
    /// Triple Data Encryption Standard algorithms implementations
    /// </summary>
    /// <Author>Yao</Author>
    /// <Date>2005/4/20</Date>public class CryptionData
    {
    // The length of Encryptionstring should be 24 byte and not be a weak key
    private string EncryptionString; // The length of initialization vector should be 8 byte
    private static Byte[] EncryptionIV = Encoding.Default.GetBytes("abcdefgh");  /// <summary>
    /// Constructor
    /// </summary>
    public CryptionData()
    {
    } /// <summary>
    /// Constructor
    /// </summary>
    /// <param name="EncryptionString">SecureKey</param>
    public CryptionData(string EncryptionString)
    {
    this.EncryptionString = EncryptionString;
    } /// <summary>
    /// Encryption method for byte array
    /// </summary>
    /// <param name="SourceData">source data</param>
    /// <returns>byte array</returns>
    public byte[] EncryptionByteData(byte[] SourceData)
    {
    byte[] returnData = null;
    try 
    {
    // Create TripleDESCryptoServiceProvider object
    TripleDESCryptoServiceProvider desProvider = new TripleDESCryptoServiceProvider(); // Set SecureKey and IV of desProvider
    byte[] byteKey = Encoding.Default.GetBytes(EncryptionString);
    desProvider.Key = byteKey;
    desProvider.IV = EncryptionIV;

    // A MemoryStream object
    MemoryStream ms = new MemoryStream();

    // Create Encryptor
    ICryptoTransform encrypto = desProvider.CreateEncryptor();

    // Create CryptoStream object
    CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Write);

    // Encrypt SourceData
    cs.Write(SourceData,0,SourceData.Length);
    cs.FlushFinalBlock();

    // Get Encryption result
    returnData = ms.ToArray();
    }
    catch(Exception ex)
    {
    throw ex;
    }

    return returnData; } /// <summary>
    /// Decryption method for byte array
    /// </summary>
    /// <param name="SourceData">source data</param>
    /// <returns>byte array</returns>
    public byte[] DecryptionByteData(byte[] SourceData)
    {
    byte[] returnData = null;
    try 
    {
    // Create TripleDESCryptoServiceProvider object
    TripleDESCryptoServiceProvider desProvider = new TripleDESCryptoServiceProvider(); // Set SecureKey and IV of desProvider
    byte[] byteKey = Encoding.Default.GetBytes(EncryptionString);
    desProvider.Key = byteKey;
    desProvider.IV = EncryptionIV;

    // A MemoryStream object
    MemoryStream ms = new MemoryStream();

    // Create Decryptor
    ICryptoTransform encrypto = desProvider.CreateDecryptor();

    // Create CryptoStream object
    CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Write); // Decrypt SourceData
    cs.Write(SourceData, 0, SourceData.Length);
    cs.FlushFinalBlock();

    // Get Decryption result
    returnData = ms.ToArray();
    }
    catch(Exception ex)
    {
    throw ex;
    }
    return returnData;

    } /// <summary>
    /// Encryption method for string
    /// </summary>
    /// <param name="SourceData">source data</param>
    /// <returns>string</returns>
    public string EncryptionStringData(string SourceData)
    {
    try
    {
    // Convert source data from string to byte array
    byte[] SourData = Encoding.Default.GetBytes(SourceData); // Encrypt byte array
    byte[] retData = EncryptionByteData(SourData); // Convert encryption result from byte array to Base64String
    return Convert.ToBase64String(retData, 0, retData.Length);
    }
    catch(Exception ex)
    {
    throw ex;
    }
    } /// <summary>
    /// Decryption method for string
    /// </summary>
    /// <param name="SourceData">source data</param>
    /// <returns>string</returns>
    public string DecryptionStringdata(string SourceData)
    {
    try
    {
    // Convert source data from Base64String to byte array
    byte[] SourData = Convert.FromBase64String(SourceData); // Decrypt byte array 
    byte[] retData = DecryptionByteData(SourData); // Convert Decryption result from byte array to string
    return Encoding.Default.GetString(retData, 0, retData.Length);
    }
    catch(Exception ex)
    {
    throw ex;
    }
    }
    }