但实际上我的输出是不同的。有人知道我在做什么错吗?
以下是 OpenSSL 如何使用它...
$ cd openssl-1.0.2-src
$ grep -R X509_subject_name_hash *
apps/x509.c: BIO_printf(STDout, "%08lx\n", X509_subject_name_hash(x));
apps/x509.c: BIO_printf(STDout, "%08lx\n", X509_subject_name_hash_old(x));
crypto/x509/x509.h:unsigned long X509_subject_name_hash(X509 *x);
crypto/x509/x509.h:unsigned long X509_subject_name_hash_old(X509 *x);
crypto/x509/x509_cmp.c:unsigned long X509_subject_name_hash(X509 *x)
crypto/x509/x509_cmp.c:unsigned long X509_subject_name_hash_old(X509 *x)
...
然后,看着apps/x509.c
:
...
} else if (subject_hash == i) {
BIO_printf(STDout, "%08lx\n", X509_subject_name_hash(x));
}
...
你的声明应该是:
unsigned long hash = X509_subject_name_hash(cert);
然后:
fprintf(stdout, "%08lx\n", hash);
此外,OpenSSL 在 OpenSSL 1.0.1 附近的某个时候改变了计算主题哈希的方式。这就是为什么有一个X509_subject_name_hash
and X509_subject_name_hash_old
。
如果您使用 OpenSSL 0.9.8 或与之比较(例如 Mac OS X 10),请参阅Generate Subject Hash of X509Certificate in Java。尽管它是 Java,但它详细介绍了主题哈希的 OpenSSL 处理。