小编ela*_*ick的帖子

C#中的Math.Cos和Math.Sin

我正在尝试一些我认为应该相当简单的事情.我有一个角度,一个位置和一个距离,我想从这些信息中找到X,Y坐标.

使用90度的示例输入,我使用以下代码将值转换为弧度:

public double DegreeToRadian(float angle)
{
  return Math.PI * angle / 180.0;
}
Run Code Online (Sandbox Code Playgroud)

这给了我1.5707963267949弧度然后当我使用

Math.Cos(radians)
Run Code Online (Sandbox Code Playgroud)

我最终得到了一个答案:6.12303176911189E-17

到底他妈发生了什么?90度的余弦应该是0,所以为什么我会得到这样的偏差...更重要的是我怎么能阻止它呢?

c# trigonometry

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

在C#和NodeJS中生成PBKDF2密钥

我正在尝试使用AES192和基于PBKDF2密码/盐的密钥在C#中加密字节数组,并在NodeJS中解密相同的数据.然而,我的密钥生成在NodeJS和C#中产生不同的结果.

C#代码如下:

    private void getKeyAndIVFromPasswordAndSalt(string password, byte[] salt, SymmetricAlgorithm symmetricAlgorithm, ref byte[] key, ref byte[] iv)
    {
        Rfc2898DeriveBytes rfc2898DeriveBytes = new Rfc2898DeriveBytes(password, salt);
        key = rfc2898DeriveBytes.GetBytes(symmetricAlgorithm.KeySize / 8);
        iv = rfc2898DeriveBytes.GetBytes(symmetricAlgorithm.BlockSize / 8);
    }

    private byte[] encrypt(byte[] unencryptedBytes, string password, int keySize)
    {
        RijndaelManaged aesEncryption = new RijndaelManaged();
        aesEncryption.KeySize = keySize;
        aesEncryption.BlockSize = 128;
        byte[] key = new byte[keySize];
        byte[] iv = new byte[128];
        getKeyAndIVFromPasswordAndSalt(password, Encoding.ASCII.GetBytes("$391Ge3%£2gfR"), aesEncryption, ref key, ref iv);
        aesEncryption.Key = key;
        aesEncryption.IV = iv;
        Console.WriteLine("iv: {0}", Convert.ToBase64String(aesEncryption.IV)); …
Run Code Online (Sandbox Code Playgroud)

c# cryptography node.js

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

事件处理程序未添加到新邮件项目

我正在尝试创建一个简单的Outlook 2010加载项,以响应新的附件事件.下面的代码仅在我取消注释MessageBox.Show行时才有效.但删除它似乎不添加事件处理程序.我对程序流的缺失是什么意味着模态消息框会影响事件处理程序的位置?

public partial class ThisAddIn
{
    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        Application.Inspectors.NewInspector += Inspectors_NewInspector;
    }

    void Inspectors_NewInspector(Outlook.Inspector Inspector)
    {
        Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;
        if (mailItem != null)
        {
            if (mailItem.EntryID == null)
            {
                mailItem.BeforeAttachmentAdd += mailItem_BeforeAttachmentAdd;
                //System.Windows.Forms.MessageBox.Show("Twice");
            }
        }
    }

    void mailItem_BeforeAttachmentAdd(Outlook.Attachment Attachment, ref bool Cancel)
    {
        Cancel = true;
    }

    private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
    {
    }
Run Code Online (Sandbox Code Playgroud)

c# add-in event-handling office-2010 outlook-addin

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