小编Dav*_*ave的帖子

DES加密/解密中的C#编码

我的主要方法运行没有错误,但是解密后的消息不正确。我几乎可以肯定我没有正确编码,但是我无法确定问题所在。任何帮助将不胜感激。

这是我的第一篇文章,因此,如果我无意间违反了规则或不遵守准则,请告诉我。

static void Main(string[] args)
{
    string unencryptedString = "cat";
    string encryptedString;
    string decryptedString;

    string password = "password";

    System.Console.WriteLine("Unencrypted String: " + unencryptedString);
    System.Console.WriteLine("Password: " + password);

    encryptedString = StandardEncryptor.Encrypt(unencryptedString, password);
    System.Console.WriteLine("Encrypted String: " + encryptedString);

    decryptedString = StandardEncryptor.Decrypt(encryptedString, password);
    System.Console.WriteLine("Decrypted String: " + decryptedString);

    System.Console.ReadLine();
}

public static string Encrypt(string message, string password)
{
    // Encode message and password
    byte[] messageBytes = ASCIIEncoding.ASCII.GetBytes(message);
    byte[] passwordBytes = ASCIIEncoding.ASCII.GetBytes(password);

    // Set encryption settings -- Use password for both key and …
Run Code Online (Sandbox Code Playgroud)

c# encoding cryptography

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

C#File.Copy抛出异常"不支持给定路径的格式"

string source = @"C:\Users\damanja\Desktop\Projects\RecStudentManagement\RecStudentManagement.Web\Reports\Templates\ContactInformationReport.xlsx";
string dest = @"C:\Users\damanja\Desktop\Projects\RecStudentManagement\RecStudentManagement.Web\Reports\Ran\damanja2012-12-17T10:14:02.0394885-06:00.xlsx";

File.Copy(source, dest, true);
Run Code Online (Sandbox Code Playgroud)

产生此异常:

The given path's format is not supported.
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪:

at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath)
   at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath)
   at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
   at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath)
   at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite)
   at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
   at RecStudentManagement.Web.Reports.ExcelReport.CopyTemplate() in C:\\Users\\damanja\\Desktop\\Projects\\RecStudentManagement\\RecStudentManagement.Web\\Reports\\ExcelReport.cs:line 52
   at RecStudentManagement.Web.Reports.ExcelReport..ctor(String fileName) in C:\\Users\\damanja\\Desktop\\Projects\\RecStudentManagement\\RecStudentManagement.Web\\Reports\\ExcelReport.cs:line 35
   at RecStudentManagement.Web.Reports.ContactInformationReport..ctor(IEnumerable`1 students, …
Run Code Online (Sandbox Code Playgroud)

.net c#

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

在C#接口实现中覆盖equals

我有一个实现接口的类,例如:

interface IInterface
{
   string PropA { get; }
   string PropB { get; }
}

class AClass : IInterface
{
   string PropA { get; protected set; }
   string PropB { get; protected set; }
}
Run Code Online (Sandbox Code Playgroud)

平等基于PropA和PropB确定.覆盖AClass的Equals方法时,我是否应该尝试将obj强制转换为AClass,如下所示:

public override bool Equals(object obj)
{
   AClass other = obj as AClass;
   return other != null 
       && AClass.PropA == other.PropA 
       && AClass.PropB == PropB;
}
Run Code Online (Sandbox Code Playgroud)

或者我应该尝试将obj强制转换为IInterface,如下所示:

public override bool Equals(object obj)
{
   IInterface other = obj as IInterface;
   return other != null 
       && AClass.PropA …
Run Code Online (Sandbox Code Playgroud)

c# equals interface-implementation

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