相关疑难解决方法(0)

C#的简单不安全双向"混淆"

我正在为某些数据寻找非常简单的混淆(如加密和解密但不一定是安全的)功能.这不是关键任务.我需要一些东西来保持诚实的人诚实,但比ROT13Base64强一点.

我更喜欢已经包含在.NET framework 2.0中的东西,所以我不必担心任何外部依赖.

我真的不想乱用公钥/私钥等等.我对加密知之甚少,但我知道我写的任何东西都不会毫无价值......事实上,我可能搞砸了数学并且让它变得微不足道.

c# obfuscation

419
推荐指数
11
解决办法
21万
查看次数

在C#中加密和解密字符串

在C#中满足以下内容的最现代(最佳)方式是什么?

string encryptedString = SomeStaticClass.Encrypt(sourceString);

string decryptedString = SomeStaticClass.Decrypt(encryptedString);
Run Code Online (Sandbox Code Playgroud)

但最小的涉及盐,键,与字节[]等混乱的大惊小怪等.

谷歌搜索和混淆我发现的东西(你可以看到类似的SO Q列表,看这是一个欺骗性的问题).

c# encryption

330
推荐指数
6
解决办法
57万
查看次数

Asp.NET Identity 2给出"无效令牌"错误

我正在使用Asp.Net-Identity-2,我正在尝试使用以下方法验证电子邮件验证码.但我收到"无效令牌"错误消息.

  • 我的应用程序的用户管理器是这样的:

    public class AppUserManager : UserManager<AppUser>
    {
        public AppUserManager(IUserStore<AppUser> store) : base(store) { }
    
        public static AppUserManager Create(IdentityFactoryOptions<AppUserManager> options, IOwinContext context)
        {
            AppIdentityDbContext db = context.Get<AppIdentityDbContext>();
            AppUserManager manager = new AppUserManager(new UserStore<AppUser>(db));
    
            manager.PasswordValidator = new PasswordValidator { 
                RequiredLength = 6,
                RequireNonLetterOrDigit = false,
                RequireDigit = false,
                RequireLowercase = true,
                RequireUppercase = true
            };
    
            manager.UserValidator = new UserValidator<AppUser>(manager)
            {
                AllowOnlyAlphanumericUserNames = true,
                RequireUniqueEmail = true
            };
    
            var dataProtectionProvider = options.DataProtectionProvider;
    
            //token life span is 3 hours …
    Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc-5 asp.net-identity-2

59
推荐指数
7
解决办法
5万
查看次数

获取IllegalBlockSizeException:使用rsa时,数据不得超过256个字节

我使用rsa密钥加密一个长字符串,我将发送到我的服务器(将使用服务器的公钥和我的私钥加密它)但它抛出一个异常,就像javax.crypto.IllegalBlockSizeException: Data must not be longer than 256 bytes 我觉得我还没有理解rsa的工作到现在为止(使用内置库是导致此问题的原因).
有人可以解释为什么抛出这个异常.是不是可以发送长字符串加密?

java encryption rsa

41
推荐指数
3
解决办法
6万
查看次数

为什么密码错误导致"填充无效且无法删除"?

我需要一些简单的字符串加密,所以我写了下面的代码(从这里有很多"灵感" ):

    // create and initialize a crypto algorithm
    private static SymmetricAlgorithm getAlgorithm(string password) {
        SymmetricAlgorithm algorithm = Rijndael.Create();
        Rfc2898DeriveBytes rdb = new Rfc2898DeriveBytes(
            password, new byte[] {
            0x53,0x6f,0x64,0x69,0x75,0x6d,0x20,             // salty goodness
            0x43,0x68,0x6c,0x6f,0x72,0x69,0x64,0x65
        }
        );
        algorithm.Padding = PaddingMode.ISO10126;
        algorithm.Key = rdb.GetBytes(32);
        algorithm.IV = rdb.GetBytes(16);
        return algorithm;
    }

    /* 
     * encryptString
     * provides simple encryption of a string, with a given password
     */
    public static string encryptString(string clearText, string password) {
        SymmetricAlgorithm algorithm = getAlgorithm(password);
        byte[] clearBytes = System.Text.Encoding.Unicode.GetBytes(clearText); …
Run Code Online (Sandbox Code Playgroud)

.net c# encryption exception

40
推荐指数
3
解决办法
7万
查看次数

使.txt文件不可读/不可编辑

我有一个程序可以保存一个带有高分的.txt文件:

 // Create a file to write to. 
string createHighscore = _higscore + Environment.NewLine;
File.WriteAllText(path, createText);

// Open the file to read from. 
string createHighscore = File.ReadAllText(path);
Run Code Online (Sandbox Code Playgroud)

问题是用户可以使用texteditor尽可能简单地编辑文件.所以我想让文件不可读/不可编辑或加密它.

我的想法是我可以将数据保存在资源文件中,但是我可以在资源文件中写入吗?或者将其保存为.dll,加密/解密或查找MD5-sum/hash.

c# encryption md5sum

36
推荐指数
5
解决办法
9892
查看次数

.NET中的密码加密/解密代码

我希望在C#中简单加密和解密密码.如何在数据库中以加密格式保存密码并通过解密检索原始格式?

.net c# encryption cryptography

27
推荐指数
2
解决办法
16万
查看次数

在App.config中加密密码

我想加密连接字符串中的密码.当我连接到DB时,连接字符串公开存储在App.config中,我需要找到一种方法来保持只加密密码.

c# ado.net entity-framework

25
推荐指数
2
解决办法
8万
查看次数

对称加密(AES):保存IV和Salt以及加密数据是否安全且正确?

在使用对称加密算法(在本例中为AES)加密和解密数据时,我试图理解如何处理和管理启动向量和盐(适用时).

我从不同的SO线程和各种其他网站推断出,IV或盐都不需要保密,只是为了防御密码分析攻击,例如蛮力攻击.考虑到这一点,我认为将伪随机IV与加密数据一起存储是可行的.我问的是我使用的方法是否合适,而且,我是否应该以同样的方式处理我目前的硬编码盐?那就是将它写在IV旁边的内存流中

我的代码:

private const ushort ITERATIONS = 300;
private static readonly byte[] SALT = new byte[] { 0x26, 0xdc, 0xff, 0x00, 0xad, 0xed, 0x7a, 0xee, 0xc5, 0xfe, 0x07, 0xaf, 0x4d, 0x08, 0x22,  0x3c };

private static byte[] CreateKey(string password, int keySize)
{
    DeriveBytes derivedKey = new Rfc2898DeriveBytes(password, SALT, ITERATIONS);
    return derivedKey.GetBytes(keySize >> 3);
}

public static byte[] Encrypt(byte[] data, string password)
{
    byte[] encryptedData = null;
    using (AesCryptoServiceProvider provider = new AesCryptoServiceProvider())
    {
        provider.GenerateIV();
        provider.Key = CreateKey(password, provider.KeySize);
        provider.Mode …
Run Code Online (Sandbox Code Playgroud)

c# encryption cryptography encryption-symmetric

22
推荐指数
2
解决办法
1万
查看次数

在C#中保存字典<String,Int32> - 序列化?

我正在编写一个C#应用程序,需要在启动时读取大约130,000(String,Int32)对到Dictionary.这些对存储在.txt文件中,因此很容易被任何人修改,这在上下文中是危险的.我想问一下是否有办法保存这个词典,以便可以合理安全地存储信息,而不会在启动时失去性能.我尝试过使用BinaryFormatter,但问题是原始程序在启动时需要125ms到250ms来读取txt中的信息并构建字典,反序列化生成的二进制文件需要2s,这本身并不太多但与原始性能相比,速度降低了8-16倍.

注意:加密很重要,但最重要的应该是从磁盘保存和读取字典的方法 - 可能来自二进制文件 - 而不必在每一行上使用Convert.ToInt32,从而提高性能.

c# binary performance serialization

17
推荐指数
1
解决办法
2万
查看次数