NodeJS 和 C# 中的 AES256 加密/解密

2024-03-17

我对以下问题的结果采取了一些自由态度:

  • .NET 中的 AES 加密并使用 Node.js 加密解密? https://stackoverflow.com/questions/17306552/aes-encrypt-in-net-and-decrypt-with-node-js-crypto
  • 从node.js解密.NET中的AES256加密数据 - 如何从密码中获取IV和Key https://stackoverflow.com/questions/12261540/decrypting-aes256-encrypted-data-in-net-from-node-js-how-to-obtain-iv-and-key
  • OpenSSL EVP_BytesToKey 方法的 C# 版本? https://stackoverflow.com/questions/8008253/c-sharp-version-of-openssl-evp-bytestokey-method

并创建了以下类文件...

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace T1.CoreUtils.Utilities
{
  public static class CryptoUtility
  {
    public static string Encrypt(string input, string passphrase = null)
    {
      byte[] key, iv;
      DeriveKeyAndIV(Encoding.ASCII.GetBytes(passphrase), null, 1, out key, out iv);

      return Convert.ToBase64String(EncryptStringToBytes(input, key, iv));
    }

    public static string Decrypt(string inputBase64, string passphrase = null)
    {
      byte[] key, iv;
      DeriveKeyAndIV(Encoding.ASCII.GetBytes(passphrase), null, 1, out key, out iv);

      return DecryptStringFromBytes(Convert.FromBase64String(inputBase64), key, iv);
    }

    private static void DeriveKeyAndIV(byte[] data, byte[] salt, int count, out byte[] key, out byte[] iv)
    {
      List<byte> hashList = new List<byte>();
      byte[] currentHash = new byte[0];

      int preHashLength = data.Length + ((salt != null) ? salt.Length : 0);
      byte[] preHash = new byte[preHashLength];

      System.Buffer.BlockCopy(data, 0, preHash, 0, data.Length);
      if (salt != null)
        System.Buffer.BlockCopy(salt, 0, preHash, data.Length, salt.Length);

      MD5 hash = MD5.Create();
      currentHash = hash.ComputeHash(preHash);

      for (int i = 1; i < count; i++)
      {
        currentHash = hash.ComputeHash(currentHash);
      }

      hashList.AddRange(currentHash);

      while (hashList.Count < 48) // for 32-byte key and 16-byte iv
      {
        preHashLength = currentHash.Length + data.Length + ((salt != null) ? salt.Length : 0);
        preHash = new byte[preHashLength];

        System.Buffer.BlockCopy(currentHash, 0, preHash, 0, currentHash.Length);
        System.Buffer.BlockCopy(data, 0, preHash, currentHash.Length, data.Length);
        if (salt != null)
          System.Buffer.BlockCopy(salt, 0, preHash, currentHash.Length + data.Length, salt.Length);

        currentHash = hash.ComputeHash(preHash);

        for (int i = 1; i < count; i++)
        {
          currentHash = hash.ComputeHash(currentHash);
        }

        hashList.AddRange(currentHash);
      }
      hash.Clear();
      key = new byte[32];
      iv = new byte[16];
      hashList.CopyTo(0, key, 0, 32);
      hashList.CopyTo(32, iv, 0, 16);
    }

    static byte[] EncryptStringToBytes(string plainText, byte[] Key, byte[] IV)
    {
      // Check arguments. 
      if (plainText == null || plainText.Length <= 0)
        throw new ArgumentNullException("plainText");
      if (Key == null || Key.Length <= 0)
        throw new ArgumentNullException("Key");
      if (IV == null || IV.Length <= 0)
        throw new ArgumentNullException("Key");
      byte[] encrypted;
      // Create an RijndaelManaged object 
      // with the specified key and IV. 
      using (RijndaelManaged rijAlg = new RijndaelManaged())
      {
        rijAlg.Key = Key;
        rijAlg.IV = IV;

        // Create a decrytor to perform the stream transform.
        ICryptoTransform encryptor = rijAlg.CreateEncryptor(rijAlg.Key, rijAlg.IV);

        // Create the streams used for encryption. 
        using (MemoryStream msEncrypt = new MemoryStream())
        {
          using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
          {
            using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
            {

              //Write all data to the stream.
              swEncrypt.Write(plainText);
            }
            encrypted = msEncrypt.ToArray();
          }
        }
      }


      // Return the encrypted bytes from the memory stream. 
      return encrypted;

    }

    static string DecryptStringFromBytes(byte[] cipherText, byte[] Key, byte[] IV)
    {
      // Check arguments. 
      if (cipherText == null || cipherText.Length <= 0)
        throw new ArgumentNullException("cipherText");
      if (Key == null || Key.Length <= 0)
        throw new ArgumentNullException("Key");
      if (IV == null || IV.Length <= 0)
        throw new ArgumentNullException("Key");

      // Declare the string used to hold 
      // the decrypted text. 
      string plaintext = null;

      // Create an RijndaelManaged object 
      // with the specified key and IV. 
      using (RijndaelManaged rijAlg = new RijndaelManaged())
      {
        rijAlg.Key = Key;
        rijAlg.IV = IV;

        // Create a decrytor to perform the stream transform.
        ICryptoTransform decryptor = rijAlg.CreateDecryptor(rijAlg.Key, rijAlg.IV);

        // Create the streams used for decryption. 
        using (MemoryStream msDecrypt = new MemoryStream(cipherText))
        {
          using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
          {
            using (StreamReader srDecrypt = new StreamReader(csDecrypt))
            {

              // Read the decrypted bytes from the decrypting stream 
              // and place them in a string.
              plaintext = srDecrypt.ReadToEnd();
            }
          }
        }

      }

      return plaintext;

    }
  }
}

从这里,我通过节点生成了以下内容:

var crypto = require('crypto');
var input = "This is î╥≤ what it is.";
var passkey= "This is my password.";
var cipher = crypto.createCipher('aes-256-cbc', passkey);
var encrypted = cipher.update(input, 'utf8', 'base64') + cipher.final('base64');
encrypted
// '9rTbNbfJkYVE2m5d8g/8b/qAfeCU9rbk09Na/Pw0bak='

input = "I am the walrus, coo coo cachoo!";
passkey = "I am a ≥ò'ÿ boy baby!";
cipher = crypto.createCipher('aes-256-cbc', passkey);
encrypted = cipher.update(input, 'utf8', 'base64') + cipher.final('base64');
// 'j/e+f5JU5yerSvO7FBJzR1tGro0Ie3L8sWYaupRW1JJhraGqBfQ9z+h85VhSzEjD'

var decipher = crypto.createDecipher('aes-256-cbc', passkey);
var plain = decipher.update(encrypted, 'base64', 'utf8') + decipher.final('utf8');
plain
// 'I am the walrus, coo coo cachoo!'

由此,我创建了以下测试用例:

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace T1.CoreUtils.Test.Utilities.Tests
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void EncryptReturnsExpectedValue1_unicode_in_plaintext()
        {
            var passkey = "This is my password.";
            var plain = "This is î╥≤ what it is.";
            var encrypted = "9rTbNbfJkYVE2m5d8g/8b/qAfeCU9rbk09Na/Pw0bak=";

            var actual = T1.CoreUtils.Utilities.CryptoUtility.Encrypt(plain, passkey);
            Assert.AreEqual(encrypted, actual);
        }

        [TestMethod]
        public void EncryptReturnsExpectedValue2_unicode_in_passkey()
        {
            var passkey = "I am a ≥ò'ÿ boy baby!";
            var plain = "I am the walrus, coo coo cachoo!";
            var encrypted = "j/e+f5JU5yerSvO7FBJzR1tGro0Ie3L8sWYaupRW1JJhraGqBfQ9z+h85VhSzEjD";

            var actual = T1.CoreUtils.Utilities.CryptoUtility.Encrypt(plain, passkey);
            Assert.AreEqual(encrypted, actual);
        }

        [TestMethod]
        public void DecryptReturnsExpectedValue1()
        {
            var passkey = "This is my password.";
            var plain = "This is î╥≤ what it is.";
            var encrypted = "9rTbNbfJkYVE2m5d8g/8b/qAfeCU9rbk09Na/Pw0bak=";

            var actual = T1.CoreUtils.Utilities.CryptoUtility.Decrypt(encrypted, passkey);
            Assert.AreEqual(plain, actual);
        }

        [TestMethod]
        public void DecryptReturnsExpectedValue2()
        {
            var passkey = "I am a ≥ò'ÿ boy baby!";
            var plain = "I am the walrus, coo coo cachoo!";
            var encrypted = "j/e+f5JU5yerSvO7FBJzR1tGro0Ie3L8sWYaupRW1JJhraGqBfQ9z+h85VhSzEjD";

            var actual = T1.CoreUtils.Utilities.CryptoUtility.Decrypt(encrypted, passkey);
            Assert.AreEqual(plain, actual);
        }
    }
}

Passes:

  • EncryptReturnsExpectedValue1_unicode_in_plaintext
  • 解密返回预期值1

Fails:

  • EncryptReturnsExpectedValue2_unicode_in_passkey
  • 解密返回预期值2

我只能猜测问题出在DeriveKeyAndIV方法。如果我自己找到它,我会尝试几种不同的方法并回答。


好的,在检查加密的 node.js 源代码后,我确定编码使用了新的 Buffer(passkey, 'binary'),它仅使用原始值 x 和 0xFF 作为所使用的字节,因此我创建了一个匹配的C# 中的方法...这是有问题的方法...

private static byte[] RawBytesFromString(string input)
{
  var ret = new List<Byte>();

  foreach (char x in input)
  {
    var c = (byte)((ulong)x & 0xFF);
    ret.Add(c);
  }

  return ret.ToArray();
}

以及更新/工作的 CryptoUtil.cs

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace T1.CoreUtils.Utilities
{
  public static class CryptoUtility
  {
    /*  Wanting to stay compatible with NodeJS
     *  http://stackoverflow.com/questions/18502375/aes256-encryption-decryption-in-both-nodejs-and-c-sharp-net/
     *  http://stackoverflow.com/questions/12261540/decrypting-aes256-encrypted-data-in-net-from-node-js-how-to-obtain-iv-and-key
     *  http://stackoverflow.com/questions/8008253/c-sharp-version-of-openssl-evp-bytestokey-method
     *  
     * var cipher = crypto.createCipher('aes-256-cbc', 'passphrase');
     * var encrypted = cipher.update("test", 'utf8', 'base64') + cipher.final('base64');
     * 
     * var decipher = crypto.createDecipher('aes-256-cbc', 'passphrase');
     * var plain = decipher.update(encrypted, 'base64', 'utf8') + decipher.final('utf8');
     */

    public static string Encrypt(string input, string passphrase = null)
    {
      byte[] key, iv;
      DeriveKeyAndIV(RawBytesFromString(passphrase), null, 1, out key, out iv);

      return Convert.ToBase64String(EncryptStringToBytes(input, key, iv));
    }

    public static string Decrypt(string inputBase64, string passphrase = null)
    {
      byte[] key, iv;
      DeriveKeyAndIV(RawBytesFromString(passphrase), null, 1, out key, out iv);

      return DecryptStringFromBytes(Convert.FromBase64String(inputBase64), key, iv);
    }

    private static byte[] RawBytesFromString(string input)
    {
      var ret = new List<Byte>();

      foreach (char x in input)
      {
        var c = (byte)((ulong)x & 0xFF);
        ret.Add(c);
      }

      return ret.ToArray();
    }

    private static void DeriveKeyAndIV(byte[] data, byte[] salt, int count, out byte[] key, out byte[] iv)
    {
      List<byte> hashList = new List<byte>();
      byte[] currentHash = new byte[0];

      int preHashLength = data.Length + ((salt != null) ? salt.Length : 0);
      byte[] preHash = new byte[preHashLength];

      System.Buffer.BlockCopy(data, 0, preHash, 0, data.Length);
      if (salt != null)
        System.Buffer.BlockCopy(salt, 0, preHash, data.Length, salt.Length);

      MD5 hash = MD5.Create();
      currentHash = hash.ComputeHash(preHash);

      for (int i = 1; i < count; i++)
      {
        currentHash = hash.ComputeHash(currentHash);
      }

      hashList.AddRange(currentHash);

      while (hashList.Count < 48) // for 32-byte key and 16-byte iv
      {
        preHashLength = currentHash.Length + data.Length + ((salt != null) ? salt.Length : 0);
        preHash = new byte[preHashLength];

        System.Buffer.BlockCopy(currentHash, 0, preHash, 0, currentHash.Length);
        System.Buffer.BlockCopy(data, 0, preHash, currentHash.Length, data.Length);
        if (salt != null)
          System.Buffer.BlockCopy(salt, 0, preHash, currentHash.Length + data.Length, salt.Length);

        currentHash = hash.ComputeHash(preHash);

        for (int i = 1; i < count; i++)
        {
          currentHash = hash.ComputeHash(currentHash);
        }

        hashList.AddRange(currentHash);
      }
      hash.Clear();
      key = new byte[32];
      iv = new byte[16];
      hashList.CopyTo(0, key, 0, 32);
      hashList.CopyTo(32, iv, 0, 16);
    }

    static byte[] EncryptStringToBytes(string plainText, byte[] Key, byte[] IV)
    {
      // Check arguments. 
      if (plainText == null || plainText.Length <= 0)
        throw new ArgumentNullException("plainText");
      if (Key == null || Key.Length <= 0)
        throw new ArgumentNullException("Key");
      if (IV == null || IV.Length <= 0)
        throw new ArgumentNullException("Key");
      byte[] encrypted;
      // Create an RijndaelManaged object 
      // with the specified key and IV. 
      using (RijndaelManaged cipher = new RijndaelManaged())
      {
        cipher.Key = Key;
        cipher.IV = IV;
        //cipher.Mode = CipherMode.CBC;
        //cipher.Padding = PaddingMode.PKCS7;

        // Create a decrytor to perform the stream transform.
        ICryptoTransform encryptor = cipher.CreateEncryptor(cipher.Key, cipher.IV);

        // Create the streams used for encryption. 
        using (MemoryStream msEncrypt = new MemoryStream())
        {
          using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
          {
            using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
            {

              //Write all data to the stream.
              swEncrypt.Write(plainText);
            }
            encrypted = msEncrypt.ToArray();
          }
        }
      }


      // Return the encrypted bytes from the memory stream. 
      return encrypted;

    }

    static string DecryptStringFromBytes(byte[] cipherText, byte[] Key, byte[] IV)
    {
      // Check arguments. 
      if (cipherText == null || cipherText.Length <= 0)
        throw new ArgumentNullException("cipherText");
      if (Key == null || Key.Length <= 0)
        throw new ArgumentNullException("Key");
      if (IV == null || IV.Length <= 0)
        throw new ArgumentNullException("Key");

      // Declare the string used to hold 
      // the decrypted text. 
      string plaintext = null;

      // Create an RijndaelManaged object 
      // with the specified key and IV. 
      using (var cipher = new RijndaelManaged())
      {
        cipher.Key = Key;
        cipher.IV = IV;
        //cipher.Mode = CipherMode.CBC;
        //cipher.Padding = PaddingMode.PKCS7;

        // Create a decrytor to perform the stream transform.
        ICryptoTransform decryptor = cipher.CreateDecryptor(cipher.Key, cipher.IV);

        // Create the streams used for decryption. 
        using (MemoryStream msDecrypt = new MemoryStream(cipherText))
        {
          using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
          {
            using (StreamReader srDecrypt = new StreamReader(csDecrypt))
            {

              // Read the decrypted bytes from the decrypting stream 
              // and place them in a string.
              plaintext = srDecrypt.ReadToEnd();
            }
          }
        }

      }

      return plaintext;

    }
  }
}

注意:更多与此相关的代码......

  • https://github.com/tracker1/T1.CoreUtils/blob/master/T1.CoreUtils/Utilities/CryptoUtility.cs https://github.com/tracker1/T1.CoreUtils/blob/master/T1.CoreUtils/Utilities/CryptoUtility.cs
  • https://github.com/tracker1/t1-coreutils-node/blob/master/lib/hashutils.js https://github.com/tracker1/t1-coreutils-node/blob/master/lib/hashutils.js

这些不属于nuget or npm分别,因为它们确实不属于那里......主要用于想法和参考。我确实需要更好地冲洗节点侧,以便它匹配。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

NodeJS 和 C# 中的 AES256 加密/解密 的相关文章

  • 为什么 C# Array.BinarySearch 这么快?

    我已经实施了一个很简单用于在整数数组中查找整数的 C 中的 binarySearch 实现 二分查找 static int binarySearch int arr int i int low 0 high arr Length 1 mid
  • 使用实体框架模型输入安全密钥

    这是我今天的完美想法 Entity Framework 中的强类型 ID 动机 比较 ModelTypeA ID 和 ModelTypeB ID 总是 至少几乎 错误 为什么编译时不处理它 如果您使用每个请求示例 DbContext 那么很
  • 类模板参数推导 - clang 和 gcc 不同

    下面的代码使用 gcc 编译 但不使用 clang 编译 https godbolt org z ttqGuL template
  • HTTPWebResponse 响应字符串被截断

    应用程序正在与 REST 服务通信 Fiddler 显示作为 Apps 响应传入的完整良好 XML 响应 该应用程序位于法属波利尼西亚 在新西兰也有一个相同的副本 因此主要嫌疑人似乎在编码 但我们已经检查过 但空手而归 查看流读取器的输出字
  • Clang 3.1 + libc++ 编译错误

    我已经构建并安装了 在前缀下 alt LLVM Clang trunk 2012 年 4 月 23 日 在 Ubuntu 12 04 上成功使用 GCC 4 6 然后使用此 Clang 构建的 libc 当我想使用它时我必须同时提供 lc
  • 不同枚举类型的范围和可转换性

    在什么条件下可以从一种枚举类型转换为另一种枚举类型 让我们考虑以下代码 include
  • C#中如何移动PictureBox?

    我已经使用此代码来移动图片框pictureBox MouseMove event pictureBox Location new System Drawing Point e Location 但是当我尝试执行时 图片框闪烁并且无法识别确切
  • WCF 中 SOAP 消息的数字签名

    我在 4 0 中有一个 WCF 服务 我需要向 SOAP 响应添加数字签名 我不太确定实际上应该如何完成 我相信响应应该类似于下面的链接中显示的内容 https spaces internet2 edu display ISWG Signe
  • 使用 Bearer Token 访问 IdentityServer4 上受保护的 API

    我试图寻找此问题的解决方案 但尚未找到正确的搜索文本 我的问题是 如何配置我的 IdentityServer 以便它也可以接受 授权带有 BearerTokens 的 Api 请求 我已经配置并运行了 IdentityServer4 我还在
  • while 循环中的 scanf

    在这段代码中 scanf只工作一次 我究竟做错了什么 include
  • 控件的命名约定[重复]

    这个问题在这里已经有答案了 Microsoft 在其网站上提供了命名指南 here http msdn microsoft com en us library xzf533w0 VS 71 aspx 我还有 框架设计指南 一书 我找不到有关
  • 如何在 C 中调用采用匿名结构的函数?

    如何在 C 中调用采用匿名结构的函数 比如这个函数 void func struct int x p printf i n p x 当提供原型的函数声明在范围内时 调用该函数的参数必须具有与原型中声明的类型兼容的类型 其中 兼容 具有标准定
  • 垃圾收集器是否在单独的进程中运行?

    垃圾收集器是否在单独的进程中启动 例如 如果我们尝试测量某段代码所花费的进程时间 并且在此期间垃圾收集器开始收集 它会在新进程上启动还是在同一进程中启动 它的工作原理如下吗 Code Process 1 gt Garbage Collect
  • 如何查看网络连接状态是否发生变化?

    我正在编写一个应用程序 用于检查计算机是否连接到某个特定网络 并为我们的用户带来一些魔力 该应用程序将在后台运行并执行检查是否用户请求 托盘中的菜单 我还希望应用程序能够自动检查用户是否从有线更改为无线 或者断开连接并连接到新网络 并执行魔
  • 如何使用 C# / .Net 将文件列表从 AWS S3 下载到我的设备?

    我希望下载存储在 S3 中的多个图像 但目前如果我只能下载一个就足够了 我有对象路径的信息 当我运行以下代码时 出现此错误 遇到错误 消息 读取对象时 访问被拒绝 我首先做一个亚马逊S3客户端基于我的密钥和访问配置的对象连接到服务器 然后创
  • 对现有视频添加水印

    我正在寻找一种用 C 在视频上加水印的方法 就像在上面写文字一样 图片或文字标签 我该怎么做 谢谢 您可以使用 Nreco 视频转换器 代码看起来像 NReco VideoConverter FFMpegConverter wrap new
  • C# 模拟VolumeMute按下

    我得到以下代码来模拟音量静音按键 DllImport coredll dll SetLastError true static extern void keybd event byte bVk byte bScan int dwFlags
  • IEnumreable 动态和 lambda

    我想在 a 上使用 lambda 表达式IEnumerable
  • 使用 Mongoose 无法找到按 ObjectId 搜索的文档

    Campaign find client id req param client id error campaigns gt if error response error error message else for campaign i
  • Windows 和 Linux 上的线程

    我在互联网上看到过在 Windows 上使用 C 制作多线程应用程序的教程 以及在 Linux 上执行相同操作的其他教程 但不能同时用于两者 是否存在即使在 Linux 或 Windows 上编译也能工作的函数 您需要使用一个包含两者的实现

随机推荐

  • 如何检查字符串是否包含从a到z的任何字母? [复制]

    这个问题在这里已经有答案了 可能的重复 C 正则表达式 检查 a z 和 A Z https stackoverflow com questions 6017778 c sharp regex checking for a z and a
  • fullCalendar 多日活动开始和结束时间

    多日活动很少有一个开始和一个结束时间 例如 伯明翰动漫展可能会持续三天 但你不能在凌晨 1 点出现 活动举办的三天中 每一天都有单独的开始和结束时间 我无法在文档中找到有关每个事件的多个开始和结束时间的任何内容 还有其他人吗 Edit 如果
  • 使用 Matplotlib 绘制网格

    我想在Python中使用Matplotlib绘制一个自定义的网格 我知道的np meshgrid函数 可以使用它来获取我想要连接的不同点的数组 但我不确定如何绘制网格 代码示例 x np linspace 0 100 100 y np li
  • 如何比较两个 X509Certificate2 c#

    如何比较两个 X509Certificate2 对象 我需要查找两个证书是否相同 它用于用户身份验证目的 我需要查找两个证书是否属于同一个人 我可以使用其序列号或指纹属性吗 或者还有其他方法吗 另外我对此很陌生 想知道使用 X509Cert
  • 为什么盒子阴影和元素之间有间隙?

    当将鼠标悬停在 Chrome 76 0 3809 100 64 位 中的按钮上时 框阴影和 img 之间会出现微弱的间隙 为什么会发生这种情况以及如何修复它 这是一张图片 以防您在代码片段中看不到它 body background colo
  • Java 中的空布局有什么问题? [复制]

    这个问题在这里已经有答案了 Bonjour 在花了无数时间在这个网站上寻找在屏幕上拖动组件的代码后 我注意到答案中出现了一个奇怪的趋势 每个人都对空布局的声音感到不寒而栗 所以我问 大家都有什么问题吗 我编写代码的时间不超过三个月 使用 S
  • 如何使用PHP处理多个文件上传

    我想使用 PHP 上传文件 但问题是我不知道要上传多少个文件 我的问题是如果我使用的话如何上传文件file
  • 如何在单个动画中缩放和旋转视图

    我试图通过使其从屏幕中心出现同时增长到其完整尺寸来呈现视图 同时以 3D 方式围绕 x 轴旋转它 当我创建视图时 我对其应用变换以确保它收缩并旋转以开始 它太小 实际上不可见 然后我尝试使用 CATransform3D 如下所示 CABas
  • 我如何知道golang中结构体的长度?

    我是 Golang 新手 我正在尝试从结构中获取许多属性 例如 type Client struct name string 1 lastName string 2 age uint 3 func main client Client na
  • 我希望“(int)null”返回0

    我怎样才能得到 0 作为整数值 int null EDIT 1 我想创建一个函数 它将返回各自数据类型中空表示的默认值 EDIT 2 我怎样才能从事这个工作scenario用于使用default 整数 值 Where 值可以为空或任何整数价
  • Angular ng-show / ng-hide 无法与 ng-bind-html 一起正常工作

    我想为 html 字符串中的元素设置 ng show 或 ng hide 并将其传递给 ng bind html 查看 但 ng show ng hide 不起作用 我的元素始终可见 这是我的控制器代码 scope my messageTr
  • jsch ChannelExec 和 ChannelShell 之间的确切区别是什么?

    有人可以告诉我之间的区别吗ChannelExec ChannelShell shell 和 exec 通道 http sourceforge net apps mediawiki jsch index php title Shell Exe
  • 使用 Sleep() 时 Perl 打印功能无法正常工作

    我有以下代码来打印 每秒模拟一个进度条 num 15 while num sleep 1 print 我现在遇到的问题是 每次循环后不打印字符 相反 所有 15 个 循环退出后立即打印 但是 如果我打印 n 它就可以正常工作 但 每次都会打
  • 阻止用户使用 jquery 或 javascript 重新加载页面 [重复]

    这个问题在这里已经有答案了 可能的重复 使用 jQuery Javascript 防止任何形式的页面刷新 https stackoverflow com questions 3527041 prevent any form of page
  • 如何摆脱“打印中的宽字符”?

    我有文件 tmp xxx与下一个内容 00000000 D0 BA D0 B8 D1 80 D0 B8 D0 BB D0 B8 D0 BA 当我读取文件内容并打印它时 出现错误 Wide character in print at 来源是
  • scikit-learn 中预计算内核的网格搜索中的嵌套交叉验证

    我有一个大小为 NxN 的预先计算的内核 我使用 GridSearchCV 来调整 SVM 的 C 参数 其中 kernel precompulated 如下 C range 10 np arange 2 9 param grid dict
  • PCL 上的 TPL,适用于 PCL 配置文件 78 的 MvvmCross

    尝试使用PCL for mvvmcross通过 Profile 78 与 TPL 合作 关于问题mvvmcross 的 PCL 上的 TPL https stackoverflow com questions 16914738 tpl on
  • Spring Boot + JPA2 + Hibernate - 启用二级缓存

    我使用 Spring Boot 1 2 5 和 JPA2 来注释实体 并将 hibernate 作为底层 JPA 实现 我想在该设置中使用二级缓存 因此实 体被注释为 javax persistence Cacheable 我还在 appl
  • Mac OS Xocks代理环境变量

    我知道可以通过网络应用程序设置袜子代理服务器 并且有一个 Mac 特定实用程序可以设置它 但如果可能的话 我更喜欢将袜子代理服务器设置为环境变量 有谁知道合适的export环境 如果有人想知道这对于 http 代理来说是可能的 例如 exp
  • NodeJS 和 C# 中的 AES256 加密/解密

    我对以下问题的结果采取了一些自由态度 NET 中的 AES 加密并使用 Node js 加密解密 https stackoverflow com questions 17306552 aes encrypt in net and decry