- Is the most widely used encoding system on the network, capable of converting any binary data into a 65-character text file
a~z,A~Z,0~9,+,/,=
Base 64The encoded result can be reversed, not safe enough
Base 64is the basic algorithm for all modern cryptographic algorithms
Terminal commands
# 将 10.jpg 进行 base64 编码,生成 10.txt 文件$ base64 10.jpg -o 10.txt# 将 10.txt 解码生成 1.jpg 文件$ base64 -D 10.txt -o 1.jpg# 将字符串 Man 进行 base64 编码$ echo -n "Man" | base64# 将字符串 TWFu 解码$ echo -n "TWFu" | base64 -D
Code implementation
/// BASE 64 编码- (NSString *)base64Encode:(NSString *)string { NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding]; return [data base64EncodedStringWithOptions:0];}/// BASE 64 解码- (NSString *)base64Decode:(NSString *)string { NSData *data = [[NSData alloc] initWithBase64EncodedString:string options:0]; return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];}
Save & Load User Information
Save User Information-(void) Saveuserinfo {Nsuserdefaults *defaults = [Nsuserdefaults Standarduserdefaults];IOS 8.0 will be written directly to the sandbox without any further use of ' [Defaults synchronize]; ' [Defaults setobject:self. Username Forkey:hmusernamekey]; NSString *pwd = [selfbase64encode:self. pwd]; [Defaults setobject:pwd forkey:hmuserpasswordkey];} ///load user under information-(void) loaduserinfo { Nsuserdefaults *defaults = [nsuserdefaults standarduserdefaults]; self. Usernametext. Text = [Defaults stringforkey:hmusernamekey]; self. Pwdtext. Text = [selfbase64decode:[defaults stringforkey:hmuserpasswordkey];}
Problems that exist
- Use
Base64 clear text that does not directly see the user's password
- But
Base64 the algorithm is public, and the algorithm is reversible, the security is not good
Base64 of encryption