1

我是 Macintosh 开发的新手。我有 NSData+connection.m 文件。该文件有更多不推荐使用的函数,如,BIO_new等。这些函数都遇到不推荐使用的错误。BIO_writeBIO_get_mem_data

- (NSString *)base64Encoding
{
    BIO * mem = BIO_new(BIO_s_mem());
    BIO * b64 = BIO_new(BIO_f_base64());
    BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
    mem = BIO_push(b64, mem);

    BIO_write(mem, [self bytes], [self length]);
    BIO_flush(mem);

    char * base64Pointer;
    long base64Length = BIO_get_mem_data(mem, &base64Pointer);

    NSString * base64String = [NSString stringWithCString:base64Pointer
                                               length:base64Length];

    BIO_free_all(mem);
    return base64String;
}

请帮我。

4

3 回答 3

4

Apple 弃用的是使用他们的OpenSSL 标头和他们的OpenSSL 动态库。原因是 OpenSSL 的界面即使在较小的修订版本中也会以不兼容的方式发生变化,因此很难在不破坏客户端代码的情况下保持最新的错误修复和安全更新。

可以做的(以及我过去所做的)是自己获取 OpenSSL,使用该版本中的功能并将其与您的应用程序捆绑在一起。

于 2013-05-09T12:13:09.687 回答
3

如果您的应用程序面向 Mac OS X 10.7 或更高版本,您可以改用SecTransform

同样值得注意的是,base64 有很多变体(维基百科文章列出不少于 13 个),这可能会让您对使用其他人的实现保持警惕,除非他们正确记录了他们的行为(IMO 的 OpenSSL 和 SecTransform 都无法完全在他们的文档中指定他们的行为)。

于 2013-05-09T13:22:21.353 回答
0

How to solve this error 'BIO_new' is deprecated in cocoa?

You solve this issue by not using Apple's version of OpenSSL located in /usr/include and /usr/lib. Its an old version - 0.9.8 - so its missing a number of features. Its loss will not be missed.

Instead, you should download, build and install the latest version of OpenSSL. You can download it from OpenSSL: Source, Tarballs.

Configure with the following (there's a more comprehensive list of options on the OpenSSL wiki at Configure Options).

$ export KERNEL_BITS=64
$ ./config no-ssl2 enable-ec_nistp_64_gcc_128 --openssldir=/usr/local
$ make all
$ sudo make install

--openssldir=/usr/local means /usr/local/ssl will be the base directory for the installation.

Later, when you compile and link, you perform the following:

  • Add /usr/local/ssl/include ans a header search path (i.e., a -I option)
  • Add /usr/local/ssl/lib ans a library search path (i.e., a -L option)

If you use -L, then be sure to use DYLD_LIBRARY_PATH when executing your program. Its like LD_PRELOAD on Linux. If you don't use DYLD_LIBRARY_PATH, then dyld will load the old, 0.9.8 version of OpenSSL located in /usr/lib; and not your updated, 1.0.1 version of OpenSSL located in /usr/local/ssl/lib/.

Better, omit -L and specify the full library paths.

  • /usr/local/ssl/lib/libssl.a
  • /usr/local/ssl/lib/libcrypto.a

This way you don't need to worry about -L and DYLD_LIBRARY_PATH. Things just work as expected.

于 2014-08-12T18:09:35.083 回答