小编Bhu*_*ika的帖子

在iOS上使用RSA公钥进行加密

我编写了一个iOS应用程序来与现有服务器通信.服务器生成RSA密钥对(公钥和私钥),并将公钥发送给客户端.

客户端(iOS应用程序)必须仅使用公钥加密,并将加密数据发送到服务器.

所以,我需要一个Objective-C函数来进行RSA加密.

输入:

  • 纯文字:你好世界!
  • 公钥:

    -----BEGIN PUBLIC KEY-----
    MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDEChqe80lJLTTkJD3X3Lyd7Fj+
    zuOhDZkjuLNPog3YR20e5JcrdqI9IFzNbACY/GQVhbnbvBqYgyql8DfPCGXpn0+X
    NSxELIUw9Vh32QuhGNr3/TBpechrVeVpFPLwyaYNEk1CawgHCeQqf5uaqiaoBDOT
    qeox88Lc1ld7MsfggQIDAQAB
    -----END PUBLIC KEY-----
    
    Run Code Online (Sandbox Code Playgroud)

处理:

+ (NSString *)encryptString:(NSString *)str publicKey:(NSString *)pubKey;
Run Code Online (Sandbox Code Playgroud)

输出:

uwGuSdCgDxAAN3M5THMrNcec3Fm/Kn+uUk7ty1s70oH0FNTAWz/7FMnEjWZYOtHe37G3D4DjqiWijyUCbRFaz43oVDUfkenj70NWm3tPZcpH8nsWYevc9a1M9GbnNF2jRlami8LLUTZiogypSVUuhcJvBZBOfea9cOonX6BG+vw=

题:

如何实现这个功能?

+ (NSString *)encryptString:(NSString *)str publicKey:(NSString *)pubKey;
Run Code Online (Sandbox Code Playgroud)

在SO和谷歌以及Apple的文档中,我已经有很长一段时间了.我发现Apple需要一个.der文件来进行加密,而不仅仅是公钥.

encryption objective-c ios

15
推荐指数
1
解决办法
2万
查看次数

自动更改字体大小以适应swift中的按钮

我试过这个,但它不起作用,文本超出按钮边界.

button.titleLabel!.adjustsFontSizeToFitWidth = true
button.titleLabel!.numberOfLines = 0
button.titleLabel!.minimumScaleFactor = 0.1
Run Code Online (Sandbox Code Playgroud)

当我尝试以下操作时,所有文本都适合,但文本仍然是小字体:

button.titleLabel!.font = UIFont(name: "Heiti TC", size: 9)
Run Code Online (Sandbox Code Playgroud)

如何让字体自动适合按钮的大小?

 func nextQuestion() {

    let currentQuestion = mcArray![questionIdx]

    answers = currentQuestion["Answers"] as! [String]
    correctAnswer = currentQuestion["CorrectAnswer"] as? String
    question = currentQuestion["Question"] as? String

    titlesForButtons()
}

func titlesForButtons() {
    for (idx,button) in answerButtons.enumerate() {
        button.titleLabel!.lineBreakMode = .ByWordWrapping

        button.titleLabel!.font = UIFont(name: "Heiti TC", size: 5)

        button.titleLabel!.numberOfLines = 0

        button.titleLabel!.minimumScaleFactor = 0.1

        button.titleLabel!.baselineAdjustment = .AlignCenters

        button.titleLabel!.textAlignment  = NSTextAlignment.Center

        button.setTitle(answers[idx], forState: .Normal)
        button.enabled = true
        button.backgroundColor …
Run Code Online (Sandbox Code Playgroud)

uibutton uifont ios swift

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

iOS从非运行状态启动应用程序后处理通知

我一直在尝试处理在我的应用程序中接收通知,但它并没有真正解决.

我用的时候didReceiveLocalNotification:(UILocalNotification *)notification.我可以接收并使用用于进入应用程序的通知,没有任何问题

但是,只有在应用程序已经运行时才激活此功能(活动,非活动,后台,并且可能已暂停,但我还没有尝试过).

现在,didFinishLaunchingWithOptions:(NSDictionary *)launchOptions您可以使用此函数[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]返回UILocalNotification.

但是,从非运行状态启动应用程序时,不会触发此事件.然后LocalNotification打开应用程序,但我无法以任何方式使用它.

现在,我的问题是:如何让它工作,所以当应用程序处于未运行状态时,我可以在启动应用程序时从通知中接收和处理通知?或许我在这里做错了吗?

以下是我的应用程序中的一些示例代码:

首先,didFinishLaunchingWithOptions功能,不幸的是,它不起作用.该功能[sharedLocalNotificationsInstance processNotification:notification]永远不会启动......

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

LocalNotificationsController *sharedLocalNotificationsInstance = [LocalNotificationsController sharedLocalNotificationsInstance];
[sharedLocalNotificationsInstance checkNotifications];

UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if ( notification != nil ) {

    // Process the received notification
    [sharedLocalNotificationsInstance processNotification:notification];

    application.applicationIconBadgeNumber = 0;
}

return YES;
}
Run Code Online (Sandbox Code Playgroud)

第二段代码:didReceiveLocalNotification函数,完美运行:我收到通知,[sharedLocalNotificationsInstance processNotification:notification]完美运行.

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{

// Used when the application launches from …
Run Code Online (Sandbox Code Playgroud)

objective-c uiapplication ios uilocalnotification

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