相关疑难解决方法(0)

加密C#.net中的查询字符串

string emailfield=txtEmail.Text.ToString();
string url = 
   "http://localhost:3076/user/Authenticate-Users.aspx?email="+emailfield;
Run Code Online (Sandbox Code Playgroud)

我想加密查询字符串,然后decrpyt.有没有办法在C#中做到这一点?

谢谢

c# asp.net

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

隐藏字符串中的密码

我正在制作一个自定义ftp客户端,它登录到一个ftp站点并转到特定文件夹以避免用户将文件放在错误的位置.

我不是很关心它,但密码只是一个字符串来启动新的ftp对象.

FtpClient ftp = new FtpClient("www.markonsolutions.com", "user", "password");
Run Code Online (Sandbox Code Playgroud)

保持密码不被窥探的最佳方法是什么?

c# security string passwords obfuscation

3
推荐指数
1
解决办法
3859
查看次数

AesManaged和RijndaelManaged

我目前正在开发一个连接到旧的Web服务的Silverlight应用程序.我们的旧网络服务使用silverlight不支持的加密工具.最后,我们决定使用AesManaged进行加密,但是,我们的Web服务不支持AesManaged.他们是一种解密AesManaged到RijndaelManaged的方法吗?

如果是,请您发布样本片段吗?您的反馈非常需要.

谢谢.

cryptography web-services aes rijndaelmanaged silverlight-4.0

3
推荐指数
1
解决办法
3949
查看次数

C#Byte []加密

我有一个Byte []字段,它是我需要加密的文件内容.没有什么特别的或花哨的,只是足以确保下一个获得它的人将无法轻易解码它.我会使用.Net Framework 4.0附带的加密,但我绝对不需要使文件比它更大.

我想过只是简单地反转数组或添加几个字节到最后......?

如果我可以避免使阵列变得更大,那将是伟大的.

有什么建议?

谢谢!

c# encryption

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

字符串序列化和反序列化问题

我正在尝试序列化/反序列化字符串。使用代码:


       private byte[] StrToBytes(string str)
       {
            BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream(); bf.Serialize(ms, str); ms.Seek(0, 0); return ms.ToArray(); } private string BytesToStr(byte[] bytes) { BinaryFormatter bfx = new BinaryFormatter(); MemoryStream msx = new MemoryStream(); msx.Write(bytes, 0, bytes.Length); msx.Seek(0, 0); return Convert.ToString(bfx.Deserialize(msx)); }

Run Code Online (Sandbox Code Playgroud)

如果我使用字符串变量,那么这两个代码可以正常工作。

但是,如果我反序列化一个字符串并将其保存到文件中,则在阅读了后面的内容并再次对其进行序列化之后,我只会得到字符串的第一部分。所以我相信我的文件保存/读取操作有问题。这是我保存/读取的代码


private byte[] ReadWhole(string fileName)
        {
            try
            {
                using (BinaryReader br = new BinaryReader(new FileStream(fileName, FileMode.Open)))
                {
                   return br.ReadBytes((int)br.BaseStream.Length);
                }
} catch (Exception) { return null; }
} private void WriteWhole(byte[] wrt,string fileName,bool …
Run Code Online (Sandbox Code Playgroud)

c# serialization

3
推荐指数
1
解决办法
6498
查看次数

c#中的AES GCM实现

我正在c#中以GCM模式实现AES密码.我的问题涉及"额外的经过身份验证的数据"(AAD).在以下代码中

http://blogs.msdn.com/b/shawnfa/archive/2009/03/17/authenticated-symmetric-encryption-in-net.aspx

目前还不清楚我应该从哪里获取AAD,以及如何在解密期间检索特定于此加密的AAD:

// Authenticated data becomes part of the authentication tag that is generated during
// encryption, however it is not part of the ciphertext.  That is, when decrypting the
// ciphertext the authenticated data will not be produced.  However, if the
// authenticated data does not match at encryption and decryption time, the
// authentication tag will not validate.
aes.AuthenticatedData = Encoding.UTF8.GetBytes("Additional authenticated data");
Run Code Online (Sandbox Code Playgroud)

任何有关如何使用此AAD的说明都将非常感激.谢谢

c# aes aes-gcm

3
推荐指数
1
解决办法
8221
查看次数

Rfc2898DeriveBytes和TripleDes

我现在了解到,PasswordDeriveBytes不赞成使用Rfc2898DeriveBytesRfc2898DeriveBytes在MSDN上查找。有一个使用的代码示例TripleDES。但是TripleDes比年龄大和弱AES。为什么他们似乎向前迈出了一步,又向后迈了一步?可以将一个刚刚替换TripleDesAESRfc2898DeriveBytes内在的联系TripleDes

.net c# cryptography

3
推荐指数
1
解决办法
433
查看次数

C#Rijndael解密返回额外的问号字符

我正在组织一些非常基本的对称加密/解密代码以供将来使用.我能够成功加密和解密...只有一个小问题.

这是我的代码,它从流中读入并解密到另一个流:

public void Encrypt(Stream input, Stream output) {
    byte[] key = Encoding.UTF8.GetBytes(_pw);
    byte[] iv = Encoding.UTF8.GetBytes(GenerateInitVector());
    RijndaelManaged rm = new RijndaelManaged();
    CryptoStream cs = new CryptoStream(
        output,
        rm.CreateEncryptor(key, iv),
        CryptoStreamMode.Write);
    int data;
    while ((data = input.ReadByte()) != -1)
        cs.WriteByte((byte) data);
    cs.Close();
}

public void Decrypt(Stream input, Stream output) {
    byte[] key = Encoding.UTF8.GetBytes(_pw);
    byte[] iv = Encoding.UTF8.GetBytes(GenerateInitVector());
    RijndaelManaged rm = new RijndaelManaged();
    CryptoStream cs = new CryptoStream(
        input,
        rm.CreateDecryptor(key, iv),
        CryptoStreamMode.Read);
    int data;
    while ((data = cs.ReadByte()) != -1) …
Run Code Online (Sandbox Code Playgroud)

c# encryption cryptography rijndaelmanaged

3
推荐指数
1
解决办法
1273
查看次数

将加密密钥和IV存储/转换为字符串

我一直在研究很多不同的C#加密示例.在大多数示例中,加密密钥以及初始化向量(IV)作为字节数组传递到加密/解密方法中.

我想将Key和IV存储为字符串.硬件安全模块中的密钥和IV作为SQL Server数据库中的nvarchar.

我一直在讨论如何正确地将Key和IV转换为字符串的问题.一些例子说使用Base64编码,而其他例子使用Encoding.UTF8.

这是一个生成IV并将其转换为Base64字符串的示例...

using (var aesProvider = new AesCryptoServiceProvider())
{
    aesProvider.GenerateIV();
    var ivBase64 = Convert.ToBase64String(aesProvider.IV);
    return ivBase64;
}
Run Code Online (Sandbox Code Playgroud)

但是,当我将此字符串表示形式传递给加密方法然后将其转换回字节数组时,以下代码无法说明IV不是正确的大小.

byte[] initVectorBytes = Encoding.UTF8.GetBytes(initializationVector);`
// intermediate code excluded for brevity
ICryptoTransform encryptor = symmetricKey.CreateEncryptor(keyBytes, initVectorBytes);
Run Code Online (Sandbox Code Playgroud)

是否有一种在字节数组和字符串表示之间来回转换加密密钥和IV的标准方法?

c# encryption

3
推荐指数
1
解决办法
1540
查看次数

在写入/读取到 c# mongo db 时加密/解密属性

只是要列出我拥有的所有信息:

总之,我要找的东西正是(直译)像这样,但兼容ASP核心(2.2)和C#的MongoDB驱动程序(2.7)。

这似乎是一个常见的要求,我很惊讶我找不到任何已经构建的东西。

这是我到目前为止所拥有的:

模型:

public class Patient
{
    //comes from the client as XXXXXXXXX, RegEx: "([0-9]{9})"
    //[MongoEncrypt]
    public EncryptedString SocialSecurityNumber { get; set; }  
}
Run Code Online (Sandbox Code Playgroud)

属性:

[AttributeUsage(AttributeTargets.Property)]
public class MongoEncryptAttribute : BsonSerializerAttribute
{
    public MongoEncryptAttribute()
    {
        SerializerType = typeof(MongoEncryptSerializer);
    }
}
Run Code Online (Sandbox Code Playgroud)

自定义序列化程序:

public interface IMongoEncryptSerializer : IBsonSerializer<EncryptedString>{ }

public class MongoEncryptSerializer : SerializerBase<EncryptedString>, IMongoEncryptSerializer
{
    private readonly string _encryptionKey;

    public MongoEncryptSerializer(IConfiguration configuration)
    {
        _encryptionKey = configuration.GetSection("MongoDb")["EncryptionKey"];
    }

    public override EncryptedString Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
    {
        var encryptedString …
Run Code Online (Sandbox Code Playgroud)

c# encryption mongodb asp.net-core

3
推荐指数
1
解决办法
1067
查看次数