2015-11-17 13:42:42 +00:00
//
// V i e w C o n t r o l l e r . s w i f t
// O p e n S S L - f o r - i O S
//
// C r e a t e d b y F e l i x S c h u l z e o n 0 4 . 1 2 . 2 0 1 0 .
// U p d a t e d b y F e l i x S c h u l z e o n 1 7 . 1 1 . 2 0 1 5 .
// C o p y r i g h t © 2 0 1 5 F e l i x S c h u l z e . A l l r i g h t s r e s e r v e d .
// W e b : h t t p : / / w w w . f e l i x s c h u l z e . d e
//
import UIKit
class ViewController : UIViewController {
@IBOutlet var textField : UITextField !
@IBOutlet var md5Label : UILabel !
@IBOutlet var sh256Label : UILabel !
@IBAction
func showInfo ( ) {
let message = " OpenSSL-Version: \( OPENSSL_VERSION_TEXT ) \n License: See include/LICENSE \n \n Copyright 2010-2015 by Felix Schulze \n http://www.felixschulze.de "
let alertController = UIAlertController ( title : " OpenSSL-for-iOS " , message : message , preferredStyle : . Alert )
alertController . addAction ( UIAlertAction ( title : " Ok " , style : . Cancel , handler : nil ) )
self . presentViewController ( alertController , animated : true , completion : nil )
}
override func viewDidLoad ( ) {
super . viewDidLoad ( )
self . title = " OpenSSL-for-iOS "
let infoButton = UIButton ( type : . InfoLight )
2016-08-09 19:01:08 +00:00
infoButton . addTarget ( self , action : #selector ( ViewController . showInfo ) , forControlEvents : . TouchDown )
2015-11-17 13:42:42 +00:00
self . navigationItem . rightBarButtonItem = UIBarButtonItem ( customView : infoButton )
2016-08-09 19:01:08 +00:00
self . textField . addTarget ( self , action : #selector ( ViewController . textFieldDidChange ) , forControlEvents : . EditingChanged )
2015-11-17 13:42:42 +00:00
self . calculateHash ( )
}
func textFieldDidChange ( ) {
self . calculateHash ( )
}
func calculateHash ( ) {
if textField . text ! . characters . count > 0 {
md5Label . text = FSOpenSSL . md5FromString ( textField . text )
sh256Label . text = FSOpenSSL . sha256FromString ( textField . text )
}
else {
md5Label . text = nil
sh256Label . text = nil
}
}
}