问题
So I was trying to compile a code which has a SHA1
function .. I included following header:
#include <openssl/sha.h>
And I got the following error while compiling:
test.c:9:5: error: 'SHA1' is deprecated: first deprecated in OS X 10.7
[-Werror,-Wdeprecated-declarations]
SHA1(msg, strlen(msg), hs);
^
But man pages still have the descriptions for that function.
Can anyone suggest any other header for a similar function ( MD5 or SHA1 )?
PS - also do I need to link any libraries while compiling using gcc?
回答1:
You can still use it. Deprecated does not mean not available. It's a recommendation to use a different hashing algorithm. You need to link to libcrypto - add -lcrypto
to libraries to link to.
If you're using more of openssl, you'll also need to link in libssl, using -lssl
.
so, for example if your test code is test.c, you would do:
gcc -o test test.c -lcrypto -lssl
回答2:
Apple have deprecated OpenSSL, but don't worry, OpenSSL is a huge project and not going away any time soon.
You can turn off the deprecated error by adding -Wno-error=deprecated-declarations
to your command line. This will keep the warnings (which is useful because it could help you catch other deprecated declarations) without causing it to error out.
There's some debate on why this happening on this post: Why is Apple Deprecating OpenSSL in MacOS 10.7 (Lion)?
来源:https://stackoverflow.com/questions/19840220/sha1-is-deprecated-first-deprecated-in-os-x-10-7