首页
社区
课程
招聘
[求助]现有解密算法(源码)自己加密的时候,总是提示长度不正确
2011-11-24 09:16 4914

[求助]现有解密算法(源码)自己加密的时候,总是提示长度不正确

2011-11-24 09:16
4914


//需要using
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using System.Security.Cryptography;
using System.IO;
using System.Data;
using System.Security;
using System.Diagnostics;
using System.Collections;

 private static TripleDESCryptoServiceProvider TDES=new TripleDESCryptoServiceProvider();

        private static SHA256Managed sha256=new SHA256Managed();

private static string Decode(byte[] p0, byte[] p1)
        {
            ICryptoTransform transform = null;
            string str;
          
                byte[] buffer = Convert.FromBase64String(Encoding.UTF8.GetString(p0));
                using (MemoryStream stream = new MemoryStream(buffer))
                {
                    byte[] buffer2 = new byte[buffer.Length + 1];
                    transform = TDES.CreateDecryptor(p1, ConvertToByteArray(p1, TDES.IV.Length));
                    using (CryptoStream stream2 = new CryptoStream(stream, transform, CryptoStreamMode.Read))
                    {
                        stream2.Read(buffer2, 0, buffer2.Length);
                    }
                    str = Encoding.UTF8.GetString(buffer2).Replace("\0", "");
                }
         
            return str;
        }

               private static byte[] ConvertToByteArray(byte[] p0)
        {
            //int length = 111;
            int length = TDES.Key.Length;
            if (p0.Length == length)
            {
                return p0;
            }
            byte[] destinationArray = new byte[(length - 1) + 1];
            Array.Copy(sha256.ComputeHash(p0), destinationArray, (int)(length - 1));
            return destinationArray;
        }

        private static byte[] ConvertToByteArray(byte[] p0, int p1)
        {
            byte[] destinationArray = new byte[(p1 - 1) + 1];
            Array.Copy(sha256.ComputeHash(Encoding.UTF8.GetBytes(Encoding.UTF8.GetString(p0))), destinationArray, (int)(p1 - 1));
            return destinationArray;
        }

//解密调用
Decode(Encoding.UTF8.GetBytes("字符串"), ConvertToByteArray(Encoding.UTF8.GetBytes("test")))


[CTF入门培训]顶尖高校博士及硕士团队亲授《30小时教你玩转CTF》,视频+靶场+题目!助力进入CTF世界

收藏
点赞0
打赏
分享
最新回复 (7)
雪    币: 43
活跃值: (20)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
testCode 2011-11-24 14:28
2
0
不知道,有没有高手过来看看
雪    币: 43
活跃值: (20)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
testCode 2011-11-25 09:39
3
0
高手呀!过来看看
雪    币: 43
活跃值: (20)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
testCode 2011-11-25 14:35
4
0
重新进行了编码,应该是可以的,
雪    币: 0
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
水晶龙 2011-11-25 14:56
5
0
这个看不懂的,呵呵呵
雪    币: 2105
活跃值: (424)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
exile 1 2011-11-25 15:59
6
0
aes一轮加密16字节吧
雪    币: 43
活跃值: (20)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
testCode 2011-11-25 22:00
7
0
有人想出加密的算法了吗
雪    币: 43
活跃值: (20)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
testCode 2011-11-26 17:17
8
0
是哪里出了问题
游客
登录 | 注册 方可回帖
返回