| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 768 人关注过本帖
标题:求助各位高手,将C#的两个代码翻译成PHP的!
只看楼主 加入收藏
pangzidog
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2009-4-1
收藏
 问题点数:0 回复次数:0 
求助各位高手,将C#的两个代码翻译成PHP的!
小弟菜鸟求助各位高手,将C#的两个代码翻译成PHP的~~
感激不尽~

using System;
using System.Collections.Generic;
using System.Web;
using System.Security.Cryptography;
using System.Text;
using

namespace SSOLab.
{
    public class SSOUtil
    {
        /// <summary>
        ///
        /// </summary>
        /// <param name="length"></param>
        /// <returns></returns>
        public static string GetRandomString(int length)
        {
            StringBuilder sb = new StringBuilder(length);

            for (int i = 0; i < length; i++)
            {
                Random random = new Random(unchecked(i * (int)(DateTime.Now.Ticks)));

                int ret = random.Next(122);

                while (ret < 48 || (ret > 57 && ret < 65) || (ret > 90 && ret < 97))
                {
                    ret = random.Next(122);
                }

                sb.Append((char)ret);
            }
            return sb.ToString();

        }


        /// <summary>
        ///
        /// </summary>
        /// <param name="text"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string DESEncrypt(string text, string key)
        {
            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
            des.Mode = System.Security.Cryptography.CipherMode.ECB;
            des.Padding = PaddingMode.Zeros;
            des.Key = ASCIIEncoding.ASCII.GetBytes(key);

            byte[] inputBuffer = Encoding.GetEncoding("UTF-8").GetBytes(text);
            byte[] outputBuffer = des.CreateEncryptor().TransformFinalBlock(inputBuffer, 0, inputBuffer.Length);

            return Convert.ToBase64String(outputBuffer);
        }

        public static string DESDecrypt(string text, string key)
        {

            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
            des.Mode = System.Security.Cryptography.CipherMode.ECB;
            des.Padding = PaddingMode.Zeros;
            des.Key = ASCIIEncoding.ASCII.GetBytes(key);

            byte[] inputBuffer = Convert.FromBase64String(text);
            byte[] outputBuffer = des.CreateDecryptor().TransformFinalBlock(inputBuffer, 0, inputBuffer.Length);

            return Encoding.GetEncoding("UTF-8").GetString(outputBuffer);
        }

        public static string GetSiteUrl()
        {
            string path = HttpContext.Current.Request.ApplicationPath;
            if (path.EndsWith("/") && path.Length == 1)
            {
                return GetHostUrl();
            }
            else
            {
                return GetHostUrl() + path;
            }
        }

        public static string GetHostUrl()
        {
            return string.Format("{0}://{1}:{2}",
                HttpContext.Current.Request.Url.Scheme,
                HttpContext.Current.Request.Url.Host,
                HttpContext.Current.Request.Url.Port);
        }
    }
}

还有一个
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using SSOLab.
using System.Web.Security;

namespace SSOLab.App2.WebApp
{
    public partial class SSOController : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(Request.Params["isSubmit"]) && Request.Params["isSubmit"] == "1")
            {
                try
                {
                    string ssoKey = "XBtyndN8yHpZCiM1eO9XtE1qii9Oey17CYosH8cM7nRnXBIBjdN811pZrtw1PfhcBDyq7S9OeHcGmWAR7ycM7aloXBCsXQhe10FgrBEwPfSndDZpGwxbL55ymWAmhycM";

                    string userInfo = SSOUtil.DESDecrypt(Request.Params["sso_userinfo"], ssoKey.Substring(ssoKey.Length / 2 - 1, 8));
                    Response.Write(userInfo);
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml(userInfo);

                    if (xmlDoc.SelectSingleNode("/userinfo/islongin").InnerText == "true")
                    {
                        FormsAuthentication.RedirectFromLoginPage(xmlDoc.SelectSingleNode("/userinfo/username").InnerText, false);
                    }
                    else
                    {
                        string returnUrl = SSOUtil.GetHostUrl() + FormsAuthentication.LoginUrl;

                        Response.Redirect(Request.Params["sso_signinurl"] + "?ReturnUrl=" + HttpUtility.UrlEncode(returnUrl));
                    }
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                }
            }
        }
    }
}
搜索更多相关主题的帖子: 翻译 代码 PHP 
2009-08-13 15:55
快速回复:求助各位高手,将C#的两个代码翻译成PHP的!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.053116 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved