小编dem*_*319的帖子

如何在Cocoa中创建字符串的MD5哈希?

我知道SHA-1是首选,但这个项目要求我使用MD5.

#include <openssl/md5.h>

- (NSString*) MD5Hasher: (NSString*) query {
    NSData* hashed = [query dataUsingEncoding:NSUTF8StringEncoding];
    unsigned char *digest = MD5([hashed bytes], [hashed length], NULL);
    NSString *final = [NSString stringWithUTF8String: (char *)digest];
    return final;
}
Run Code Online (Sandbox Code Playgroud)

我从StackOverflow上的另一个类似问题的答案得到了这个代码,但是当程序在返回final时中断时,我从GDB得到以下错误;

(gdb) p digest
$1 = (unsigned char *) 0xa06310e4 "\0206b\260/\336\316^\021\b\a/9\310\225\204"
(gdb) po final
Cannot access memory at address 0x0
(gdb) po digest

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0xb0623630
0x98531ed7 in objc_msgSend ()
The program being debugged …
Run Code Online (Sandbox Code Playgroud)

hash cocoa md5 objective-c

40
推荐指数
3
解决办法
5万
查看次数

NotificationListenerService:getActiveNotifications上的NullPointerException

我正在尝试根据本教程在我的应用程序中实现NotificationListenerService:http://www.kpbird.com/2013/07/android-notificationlistenerservice.html,但是在调用getActiveNotifications时我遇到了NullPointerException.

Caused by: java.lang.NullPointerException
at android.os.Parcel.readException(Parcel.java:1437)
at android.os.Parcel.readException(Parcel.java:1385)


at android.app.INotificationManager$Stub$Proxy.getActiveNotificationsFromListener(INotificationManager.java:500)
at android.service.notification.NotificationListenerService.getActiveNotifications(NotificationListenerService.java:149)
at com.rootsoft.rsnotificationservice.RSNotificationService.activeNot(RSNotificationService.java:85)
at com.rootsoft.rsnotificationservice.RSNotificationService.access$0(RSNotificationService.java:81)
at com.rootsoft.rsnotificationservice.RSNotificationService$1.onReceive(RSNotificationService.java:105)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:763)
... 9 more
Run Code Online (Sandbox Code Playgroud)

我正在向服务发送广播,该广播应生成所有通知的列表:

private void activeNot () {
    List l = new List();
    l.Initialize();

    for (StatusBarNotification sbn : getActiveNotifications() ) { <---- Error happens here
        l.Add(sbn);
    }

    Log.i("B4A", "List created.");


    }
}
Run Code Online (Sandbox Code Playgroud)

java notifications android

10
推荐指数
1
解决办法
5227
查看次数

SSL证书,不通过thrift进行身份验证,但可以通过浏览器进行验证

这是我生成SSL证书,密钥等的方式:

openssl genrsa -out server.key 1024
openssl rsa -in server.key -out new_key.pem
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 10000 -in server.csr -signkey new_key.pem -out server.crt
Run Code Online (Sandbox Code Playgroud)

这有效,我可以看到chrome的输出,虽然我得到一个警告,我将首先得到病毒.

openssl s_server -cert server.crt -www -key new_key.pem
Run Code Online (Sandbox Code Playgroud)

这是服务器的一个片段.我会说实话,我不确定每条线路到底在做什么,尽管我有个好主意:

socketFactory->server(true); // this is the server
socketFactory->authenticate(false); // no auth?
socketFactory->loadCertificate("server.crt"); 
socketFactory->loadPrivateKey("new_key.pem");
Run Code Online (Sandbox Code Playgroud)

客户:

socketFactory->loadTrustedCertificates("server.crt");
socketFactory->authenticate(true); //auth? wierd, right? This guy does this:[1]
Run Code Online (Sandbox Code Playgroud)

[1] http://permalink.gmane.org/gmane.comp.lib.thrift.user/1651

如果我loadTrustedCertificates在客户端注释掉,那么我将获得SSL未经验证的证书例外.留下该行,我得到一个auth失败异常.

这里有两个更长的代码片段,它们将上述片段放在更好的视角中.
服务器:

shared_ptr<SkullduggeryHandler> handler(new SkullduggeryHandler());
shared_ptr<TBufferedTransportFactory> transportFactory =
        shared_ptr<TBufferedTransportFactory>(new TBufferedTransportFactory());
shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
shared_ptr<TProcessor> …
Run Code Online (Sandbox Code Playgroud)

c++ ssl openssl thrift

8
推荐指数
1
解决办法
4116
查看次数

在Cocoa中,main.m类的目的是什么?

它只是坐在那里......我如何独立于UI动作运行代码(如同,不仅仅是响应按钮按下)?我正在尝试初始化一些对象并在唤醒.FromNib之前运行一些脚本.我该怎么做呢?

cocoa objective-c

4
推荐指数
1
解决办法
4878
查看次数

为什么我的NSApplicationDelegate类中的applicationWillFinishLaunching从未被调用?

的main.m

#import <Cocoa/Cocoa.h>

int main(int argc, char *argv[])
{
    return NSApplicationMain(argc,  (const char **) argv);
}
Run Code Online (Sandbox Code Playgroud)

CoolClass.h

#import <Cocoa/Cocoa.h>

@interface CoolClass : NSObject <NSApplicationDelegate> {

}
- (void) applicationDidFinishLaunching : (NSNotification *) aNotification;
@end
Run Code Online (Sandbox Code Playgroud)

CoolClass.m

#import "CoolClass.h"

@implementation CoolClass
- (void) applicationDidFinishLaunching : (NSNotification *) aNotification {
    NSLog(@"THIS SHOULD BE PRINTED TO THE DEBUG CONSOLE");
}

@end
Run Code Online (Sandbox Code Playgroud)

我也试过"applicationWillFinishLaunching",但仍然没有运气.任何帮助都将不胜感激.谢谢.

xcode cocoa delegates objective-c

2
推荐指数
2
解决办法
1250
查看次数

为什么这个NSTask terminationStatus返回一个nil值?

我知道任务返回一个标准错误的值,我可以通过输入"echo $?"看到 在手动运行任务后在终端中.

现在这段代码:

[aTask launch];
[aTask waitUntilExit];
int status = [aTask terminationStatus];
Run Code Online (Sandbox Code Playgroud)

看起来不错,但gdb说状态是0x0的位置,无法访问.有人知道Xcode中NSTask对象中的任何错误吗?难道我做错了什么?

谢谢你的回复.

cocoa objective-c

0
推荐指数
1
解决办法
1108
查看次数

标签 统计

cocoa ×4

objective-c ×4

android ×1

c++ ×1

delegates ×1

hash ×1

java ×1

md5 ×1

notifications ×1

openssl ×1

ssl ×1

thrift ×1

xcode ×1