The default keyboard displayed in most Chinese applications is the Simplified Chinese Input Method keyboard. When you enter the user name and password, if you use the simplified Chinese Input Method keyboard and enter the user name and password of English and digital characters, the system input method is automatically started to automatically correct the prompt, and the user's input records are cached.
The most convenient way to obtain the system keyboard cache is to use the system input method to automatically correct the string input records.
Cache file address:/private/var/mobile/Library/Keyboard/dynamic-text.dat
Export the cached file and view the content. We are delighted to find that all input records are stored in plaintext. Because the system does not process all user input records as sensitive information such as passwords.
In general, a regular iPhone user's dynamic-text.dat file, the high-frequency appearance string is the user name and password.
Therefore, generally, the system keyboard is not used when the bank client app enters the password, but the custom keyboard is used for two reasons:
1) prevent third parties from reading the system keyboard Cache
2) prevent screen recording (without pressing your own keyboard keys)
So how to implement a custom security keyboard? The general idea is as follows:
1) first capture the pop-up and recall notifications of the system keyboard
2) create a more advanced window to block the system keyboard
3) a weak reference switching focus id <UITextInput> textInput must be thrown.
A simple secure keyboard model is provided below:
@interface WQSafeKeyboard : UIWindow@property (nonatomic, weak, setter = focusOnTextFiled:) UITextField *textFiled;+ (WQSafeKeyboard *)deploySafeKeyboard;@end@interface WQSafeKeyboard()@property (nonatomic, strong)WQInterKeyboard *keyboard;@end@implementation WQSafeKeyboard+ (WQSafeKeyboard *)deploySafeKeyboard{ WQSafeKeyboard *kb = [[WQSafeKeyboard alloc]init]; [kb addObserver]; return kb;}- (instancetype)init{ if (self = [super init]) { self.windowLevel = UIWindowLevelAlert; self.frame = CGRectZero; self.rootViewController = self.keyboard; } return self;}- (void)dealloc{ [[NSNotificationCenter defaultCenter] removeObserver:self];}- (WQInterKeyboard *)keyboard{ if (!_keyboard) { _keyboard = [[WQInterKeyboard alloc]init]; } return _keyboard;}- (void)focusOnTextFiled:(UITextField *)textFiled{ _textFiled = textFiled; self.keyboard.textField = _textFiled;}- (void)addObserver{ [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];}- (void)keyboardWillShow:(NSNotification *)notification{ if (![self.textFiled isFirstResponder]) { return; } [self keyboardAnimationWithNotification:notification];}- (void)keyboardWillHide:(NSNotification *)notification{ if (![self.textFiled isFirstResponder]) { return; } [self keyboardAnimationWithNotification:notification];}- (void)keyboardAnimationWithNotification:(NSNotification *)notification{ [self makeKeyAndVisible]; NSDictionary *userInfo = [notification userInfo]; CGRect kbFrame_end,kbFrame_begin; NSTimeInterval animationDuration; UIViewAnimationCurve animationCurve; [userInfo[UIKeyboardFrameEndUserInfoKey] getValue:&kbFrame_end]; [userInfo[UIKeyboardFrameBeginUserInfoKey] getValue:&kbFrame_begin]; [userInfo[UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve]; [userInfo[UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration]; self.frame = [self resizeFrameToAdjust:kbFrame_begin]; [UIView animateWithDuration:animationDuration delay:0 options:(animationCurve<<16) animations:^{ self.frame = [self resizeFrameToAdjust:kbFrame_end]; }completion:^(BOOL finished) { }]; if ([notification.name isEqualToString:UIKeyboardWillHideNotification]) { [self resignKeyWindow]; }}- (CGRect)resizeFrameToAdjust:(CGRect)frame{ if ([[UIApplication sharedApplication] isStatusBarHidden] ) return frame; if (SYSTEM_VERSION_LESS_THAN(@"7.0")) { frame = CGRectMake(frame.origin.x, frame.origin.y - STATUSBAR_HEIGHT, frame.size.width, frame.size.height); } return frame;}@end