- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在尝试使用 CNG API 和来自 Microsoft 证书存储的证书对带有 ECDSA 的文件进行签名。我已经阅读了很多文档并且几乎完成了但是我对从证书中导入私钥感到困惑。我已经用 RSA 完成了同样的事情,但它的完成方式似乎非常不同。这是我到目前为止的代码:
static void signFile()
{
X509Certificate2 myCert =
selectCert(StoreName.My,
StoreLocation.CurrentUser,
"Select a Certificate",
"Please select a certificate from the list below:");
Console.Write("Path for file to sign: ");
string path = Console.ReadLine();
TextReader file = null;
try
{
file = new StreamReader(path);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.Write("\nPress any key to return to the main menu: ");
Console.ReadKey();
}
UnicodeEncoding encoding = new UnicodeEncoding();
byte[] data = encoding.GetBytes(file.ReadToEnd());
ECDsaCng dsa = new ECDsaCng(
CngKey.Import(StringToByteArray(myCert.PrivateKey.ToString()),
CngKeyBlobFormat.EccPrivateBlob,
CngProvider.MicrosoftSoftwareKeyStorageProvider));
dsa.HashAlgorithm = CngAlgorithm.Sha384;
byte[] sig = dsa.SignData(data);
TextWriter signatureFile = new StreamWriter("signature.txt");
signatureFile.WriteLine("-----BEGIN SHA384 SIGNATURE-----" +
ByteArrayToString(sig) +
"-----END SHA384 SIGNATURE-----");
signatureFile.Close();
}
我得到了错误
System.NotSupportedException: The certificate key algorithm is not supported.
我的证书是 ECDSA_P256 sha384ECDSA,具有以下扩展名:
Digital Signature, Non-repudiation, independent signing revocation list (CRL), CRL Signing (CRL) (c2)
Server Authentication (1.3.6.1.5.5.7.3.1)
Client Authentication (1.3.6.1.5.5.7.3.2)
Code Signing (1.3.6.1.5.5.7.3.3)
Unknown Key Usage (1.3.6.1.4.1.311.2.1.22)
Unknown Key Usage (1.3.6.1.4.1.311.2.1.21)
IKE-intermediary IP-security (1.3.6.1.5.5.8.2.2)
看起来好像证书是问题所在,但我不确定是否是代码问题。
这是我的带有公钥的证书:
Certificate:
Data:
Version: 3 (0x2)
Serial Number: 2 (0x2)
Signature Algorithm: ecdsa-with-SHA384
Issuer: C=##, O=#######, OU=#####, OU=#####, CN=###########
Validity
Not Before: Apr 27 16:35:51 2012 GMT
Not After : Apr 26 16:35:51 2017 GMT
Subject: C=##, O=###########, OU=#####, CN=#############
Subject Public Key Info:
Public Key Algorithm: id-ecPublicKey
Public-Key: (256 bit)
pub:
04:fc:d5:ce:ad:1f:0c:19:b9:3d:2b:bd:7d:f0:8c:
44:46:db:e3:42:14:b1:1a:9f:7c:ab:e1:be:ad:a5:
0c:03:2d:0f:ff:3f:10:d4:69:eb:4c:82:a1:2a:61:
56:45:03:04:a6:49:f7:16:6e:dd:60:22:c6:20:c5:
4d:44:49:21:41
ASN1 OID: prime256v1
X509v3 extensions:
X509v3 Key Usage: critical
Digital Signature, Non Repudiation, CRL Sign
X509v3 Extended Key Usage: critical
TLS Web Server Authentication, TLS Web Client Authentication, Co
de Signing, Microsoft Commercial Code Signing, Microsoft Individual Code Signing
, 1.3.6.1.5.5.8.2.2
X509v3 Authority Key Identifier:
DirName:/C=##/O=#######/OU=#####/OU=#####/CN=######
serial:01
X509v3 Subject Key Identifier:
B7:A8:F9:55:9A:43:9E:BE:1C:4B:62:52:91:C2:F1:39:72:E1:CE:1B
X509v3 Basic Constraints: critical
CA:FALSE
Signature Algorithm: ecdsa-with-SHA384
30:81:88:02:42:01:75:55:f3:64:f9:aa:2a:66:55:b1:ca:dc:
86:ac:1f:7d:2a:ec:10:87:db:74:88:0e:77:e3:18:82:15:a7:
32:91:1a:2d:ea:07:2e:78:8d:dc:8a:18:3c:2b:5a:9b:6a:0f:
97:f6:f8:8d:c5:fc:0e:9f:20:e9:b0:16:90:1a:c4:58:ac:02:
42:01:dc:b3:88:ae:44:54:c4:e0:b7:c2:37:88:0b:19:6b:96:
99:f7:21:12:45:12:21:e5:ab:83:39:a6:47:3a:08:87:b0:fa:
0e:31:1b:97:83:8d:65:30:a1:43:c1:82:27:77:6e:93:89:1b:
bd:57:b1:7a:54:9e:cc:e1:44:cc:74:16:c5
最佳答案
.NET 4.6.1 核心需求解决了这个问题。新代码将是
...
byte[] sig;
using (ECDsa ecdsa = cert.GetECDsaPrivateKey())
{
if (ecdsa == null) throw new Exception("Not an ECDSA cert, or has no private key");
sig = ecdsa.SignData(data, HashAlgorithmName.SHA384);
}
.NET 4.6.1 还解决了某些证书 key 作为 ECDH 返回并因此失败的问题。 (好吧,它没有解决一些私钥被认为是 ECDH 的问题——这与 Server Auth EKU 无关,但这是一个很好的猜测——但认为这些 key 现在有效)。
关于c# - 使用存储 C#.Net CNG 中的 key 的 ECDSA 签名文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10490263/
我需要创建由“根”证书(自签名,ECDSA)签名的“客户端”ECDSA 证书。“根”证书是按照 Translating Elliptic Curve parameters (BC to MS) 中的描
理论上,如果拥有公钥、签名和已签名的数据并且哈希算法已知,则应该可以验证一段数据的签名。 我有二进制格式的所有这些组件。有人知道验证此签名的最简单方法吗?打开SSL? Python?一个例子会很棒。不
我正在使用ECC证书来观察TLS是如何工作的,谁能帮我区分ECDH-ECDSA-AES128-SHA256和 ECDHE-ECDSA-AES128-SHA256 . 使用时ECDHE-ECDSA-AE
我在执行以下操作时遇到问题: 使用 Python 为 ECDSA SECP256k1 曲线创建公私钥对,并将其打印在终端上。 在 Python 脚本和 visual studio(使用 micro-e
我正在尝试生成用于加密芯片的“原始”、未编码的 ECDSA 签名。目标是在主机 pc 上签署某些内容,然后将其发送到芯片进行验证。但是,我遇到了一个小问题。我的理解是 ECDSA 签名应该是 64 个
我需要使用 ECDSA 算法对消息进行签名并在 java 中发送给接收者。然后,接收方应验证发送方的签名。 因此,为此,接收方拥有发送方的公钥,但在通过以下命令将 java.security.Publ
我正在使用创建 key 对 ECDSA::Signer signer; signer.AccessKey().Initialize(randomGeneratorM, ASN1::secp160r1(
我只需要为 ECDSA 获取私钥和公钥对。 Stanford Javascript Crypto Library 以非标准方式 ( https://groups.google.com/forum/
我一直在为以太坊交易管理器编写签名者服务,我需要使用 Google KMS Golang APIs 签署以太坊交易。 .我将在下面尝试总结我面临的问题。 Ethereum 在 R 中需要紧凑的 RLP
我使用以下两行来生成 ECDSA 私钥的十六进制: openssl ecparam -genkey -name secp256k1 -out data.pem openssl ec -in data.
我正在使用 python 和 cryptography.io 来签署和验证消息。我可以通过以下方式获得签名的 DER 编码字节表示: cryptography_priv_key.sign(messag
是否有为 JWK 创建指纹(又名指纹)的标准规范方法? 从我阅读的内容来看,该标准似乎没有定义 kid应该指定,我觉得很奇怪。对我来说,它是最重要的,因为它是一个确定性的值,而不是一个需要查找表的值,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 关闭 8 年前。 Improve
我想知道ECDSA签名和公钥的数据格式是什么规范(或标准)定义的? 我正在 java 卡上测试 ECDSA 签名。我发现签名和公钥值中有一个TLV格式。 * Public key (TV format
我正在尝试创建一个数字证书,该证书将使用 EC key 而不是来自 RSA 的 key 进行自签名,并遵循这些 SO link1和 link2 。我将 link1 中给出的 RSA 签名算法替换为 E
我正在尝试创建一个数字证书,该证书将使用 EC key 而不是来自 RSA 的 key 进行自签名,并遵循这些 SO link1和 link2 。我将 link1 中给出的 RSA 签名算法替换为 E
以下网站经常被引用,我认为是准确的: https://gobittest.appspot.com/Address 我正在尝试在 Golang 中重现这些步骤,但第一步失败:-( 有人可以向我提供一个
我试图从私钥生成公共(public) ECDSA key ,但我没有在互联网上找到关于如何执行此操作的太多帮助。几乎一切都是为了从公钥规范生成公钥,但我不知道如何获得它。到目前为止,这是我整理的内容:
是否有任何库支持从 javascript(前端)的私钥派生 ecdsa 公钥? (有了私钥,我们就可以生成对应的公钥) 我研究了localethereum white paper ,我想实现加密层。
来自OpenSSL documentation 使用命名曲线 prime256v1(又名 P-256)创建给定 SHA-256 哈希值的 ECDSA 签名。 第二步:使用 ECDSA_do_sign(
我是一名优秀的程序员,十分优秀!