ruby网站改版.NET,大牛们来出个点子

haoranchangfeng haoranchangfeng 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
因为业务需要,现在要用.NET来改版一个Ruby网站,首先做登录的时候就遇到了问题,
他原本的加密是

class Crypt
#discuz encrypt function
def self.encrypt(txt, key)
encrypt_key = Digest::MD5.hexdigest(rand(32000).to_s);
ctr = 0
tmp = ''
Range.new(0,txt.length-1).each do |i|
ctr = (ctr==encrypt_key.length ? 0 : ctr)
tmp += encrypt_key[ctr].chr+(txt[i] ^ encrypt_key[ctr]).chr
ctr = ctr+1
end
Base64.encode64(self.key(tmp,key));
end


def self.decrypt(txt,key)
txt = self.key(Base64.decode64(txt),key)
tmp = ''
0.step(txt.length-1,2) do |i|
data = txt[i] ^ txt[i+1]
tmp += data.chr
end
x = self.decode(tmp)
print x.inspect
x
end


def self.key(txt, encrypt_key)
encrypt_key = Digest::MD5.hexdigest(encrypt_key);
ctr = 0;
tmp = '';
0.upto(txt.length-1) do |i|
ctr = ctr==encrypt_key.length ? 0 : ctr
tmp += (txt[i] ^ encrypt_key[ctr]).chr
ctr = ctr+1
end
tmp
end

def self.encode(hash)
raise "passport encode must recieve a hash" unless hash.instance_of? Hash
str = []
hash.each do |key,value|
str << "#{key}="+CGI::escape(value.to_s)
end
str.join("&")
end

def self.decode(txt)
txt.gsub!(/.+\?/,'')
params = Hash.new([].freeze)
txt.split(/[&;]/n).each do |pairs|
key, value = pairs.split('=',2).collect{|v| CGI::unescape(v) }
key = key.to_sym
if params.has_key?(key)
params[key].push(value)
else
params[key] = value
end
end
params
end
#end discuz encrypt function
end



怎么样把这个方法翻译为 C#语言的?或者怎么样在C#中加密才能匹配的对,登录进去?
不知道我描述的清楚不,大家有经验的帮帮忙..
...全文
评论 6
收藏 已收藏
分享
返回顶部
haoranchangfeng
C# 111,129 成员 642,538 内容