aboutsummaryrefslogtreecommitdiffstats
path: root/examples/c/hash.c
diff options
context:
space:
mode:
authorMichal Rokos <m.rokos@sh.cvut.cz>2002-06-04 06:44:42 +0000
committerMichal Rokos <m.rokos@sh.cvut.cz>2002-06-04 06:44:42 +0000
commita5180750f7ab485fba73dd6e9861536adf3b693b (patch)
treecd2cea7862bed69939cb64d20346a3f975b5a9cc /examples/c/hash.c
parentbc603852659675cd0c7420dd4d126780f7ba6ee2 (diff)
downloadruby-openssl-history-a5180750f7ab485fba73dd6e9861536adf3b693b.tar.gz
Initial revision
Diffstat (limited to 'examples/c/hash.c')
-rw-r--r--examples/c/hash.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/examples/c/hash.c b/examples/c/hash.c
new file mode 100644
index 0000000..76f2fa4
--- /dev/null
+++ b/examples/c/hash.c
@@ -0,0 +1,51 @@
+/*
+ * $Id$
+ * RubySSL project
+ * Copyright (C) 2001 Michal Rokos <m.rokos@sh.cvut.cz>
+ * All rights reserved.
+ */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details. (You can find the licence
+ * in LICENCE.txt file.)
+ */
+#include <openssl/ssl.h>
+
+int main(int argc, char *argv[])
+{
+ BIO *in = NULL, *out = NULL;
+ X509 *x509 = NULL;
+ ASN1_BIT_STRING *key = NULL;
+ ASN1_OCTET_STRING *digest = NULL;
+ unsigned char dig[EVP_MAX_MD_SIZE];
+ EVP_MD_CTX md;
+ unsigned int dig_len;
+ char *txt = NULL;
+
+ in = BIO_new_file("./01cert.pem", "r");
+ out = BIO_new(BIO_s_file());
+ BIO_set_fp(out, stdout, BIO_NOCLOSE|BIO_FP_TEXT);
+
+ x509 = PEM_read_bio_X509(in, NULL, NULL, NULL);
+ key = x509->cert_info->key->public_key;
+
+ ASN1_STRING_print(out, key);
+ BIO_printf(out, "\n===\n");
+
+ EVP_DigestInit(&md, EVP_sha1());
+ EVP_DigestUpdate(&md, key->data, key->length);
+ EVP_DigestFinal(&md, dig, &dig_len);
+
+ txt = hex_to_string(dig, dig_len);
+ BIO_printf(out, "%s\n===\n", txt);
+ return 0;
+}
+//i2v_ ... as STACK_OF(CONF_VALUE) for easy printing
+