-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
qingjin
committed
Mar 18, 2016
0 parents
commit eeafd75
Showing
4 changed files
with
839 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,253 @@ | ||
// !$*UTF8*$! | ||
{ | ||
archiveVersion = 1; | ||
classes = { | ||
}; | ||
objectVersion = 46; | ||
objects = { | ||
|
||
/* Begin PBXBuildFile section */ | ||
7F4811C51C9BE3FE00252CB6 /* RSAEncryptor.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7F4811C41C9BE3FE00252CB6 /* RSAEncryptor.h */; }; | ||
7F4811C71C9BE3FE00252CB6 /* RSAEncryptor.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F4811C61C9BE3FE00252CB6 /* RSAEncryptor.m */; }; | ||
/* End PBXBuildFile section */ | ||
|
||
/* Begin PBXCopyFilesBuildPhase section */ | ||
7F4811BF1C9BE3FE00252CB6 /* CopyFiles */ = { | ||
isa = PBXCopyFilesBuildPhase; | ||
buildActionMask = 2147483647; | ||
dstPath = "include/$(PRODUCT_NAME)"; | ||
dstSubfolderSpec = 16; | ||
files = ( | ||
7F4811C51C9BE3FE00252CB6 /* RSAEncryptor.h in CopyFiles */, | ||
); | ||
runOnlyForDeploymentPostprocessing = 0; | ||
}; | ||
/* End PBXCopyFilesBuildPhase section */ | ||
|
||
/* Begin PBXFileReference section */ | ||
7F4811C11C9BE3FE00252CB6 /* libRSAEncryptor.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRSAEncryptor.a; sourceTree = BUILT_PRODUCTS_DIR; }; | ||
7F4811C41C9BE3FE00252CB6 /* RSAEncryptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RSAEncryptor.h; sourceTree = "<group>"; }; | ||
7F4811C61C9BE3FE00252CB6 /* RSAEncryptor.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RSAEncryptor.m; sourceTree = "<group>"; }; | ||
/* End PBXFileReference section */ | ||
|
||
/* Begin PBXFrameworksBuildPhase section */ | ||
7F4811BE1C9BE3FE00252CB6 /* Frameworks */ = { | ||
isa = PBXFrameworksBuildPhase; | ||
buildActionMask = 2147483647; | ||
files = ( | ||
); | ||
runOnlyForDeploymentPostprocessing = 0; | ||
}; | ||
/* End PBXFrameworksBuildPhase section */ | ||
|
||
/* Begin PBXGroup section */ | ||
7F4811B81C9BE3FE00252CB6 = { | ||
isa = PBXGroup; | ||
children = ( | ||
7F4811C31C9BE3FE00252CB6 /* RSAEncryptor */, | ||
7F4811C21C9BE3FE00252CB6 /* Products */, | ||
); | ||
sourceTree = "<group>"; | ||
}; | ||
7F4811C21C9BE3FE00252CB6 /* Products */ = { | ||
isa = PBXGroup; | ||
children = ( | ||
7F4811C11C9BE3FE00252CB6 /* libRSAEncryptor.a */, | ||
); | ||
name = Products; | ||
sourceTree = "<group>"; | ||
}; | ||
7F4811C31C9BE3FE00252CB6 /* RSAEncryptor */ = { | ||
isa = PBXGroup; | ||
children = ( | ||
7F4811C41C9BE3FE00252CB6 /* RSAEncryptor.h */, | ||
7F4811C61C9BE3FE00252CB6 /* RSAEncryptor.m */, | ||
); | ||
path = RSAEncryptor; | ||
sourceTree = "<group>"; | ||
}; | ||
/* End PBXGroup section */ | ||
|
||
/* Begin PBXNativeTarget section */ | ||
7F4811C01C9BE3FE00252CB6 /* RSAEncryptor */ = { | ||
isa = PBXNativeTarget; | ||
buildConfigurationList = 7F4811CA1C9BE3FE00252CB6 /* Build configuration list for PBXNativeTarget "RSAEncryptor" */; | ||
buildPhases = ( | ||
7F4811BD1C9BE3FE00252CB6 /* Sources */, | ||
7F4811BE1C9BE3FE00252CB6 /* Frameworks */, | ||
7F4811BF1C9BE3FE00252CB6 /* CopyFiles */, | ||
); | ||
buildRules = ( | ||
); | ||
dependencies = ( | ||
); | ||
name = RSAEncryptor; | ||
productName = RSAEncryptor; | ||
productReference = 7F4811C11C9BE3FE00252CB6 /* libRSAEncryptor.a */; | ||
productType = "com.apple.product-type.library.static"; | ||
}; | ||
/* End PBXNativeTarget section */ | ||
|
||
/* Begin PBXProject section */ | ||
7F4811B91C9BE3FE00252CB6 /* Project object */ = { | ||
isa = PBXProject; | ||
attributes = { | ||
LastUpgradeCheck = 0720; | ||
ORGANIZATIONNAME = qianhongqiang; | ||
TargetAttributes = { | ||
7F4811C01C9BE3FE00252CB6 = { | ||
CreatedOnToolsVersion = 7.2; | ||
}; | ||
}; | ||
}; | ||
buildConfigurationList = 7F4811BC1C9BE3FE00252CB6 /* Build configuration list for PBXProject "RSAEncryptor" */; | ||
compatibilityVersion = "Xcode 3.2"; | ||
developmentRegion = English; | ||
hasScannedForEncodings = 0; | ||
knownRegions = ( | ||
en, | ||
); | ||
mainGroup = 7F4811B81C9BE3FE00252CB6; | ||
productRefGroup = 7F4811C21C9BE3FE00252CB6 /* Products */; | ||
projectDirPath = ""; | ||
projectRoot = ""; | ||
targets = ( | ||
7F4811C01C9BE3FE00252CB6 /* RSAEncryptor */, | ||
); | ||
}; | ||
/* End PBXProject section */ | ||
|
||
/* Begin PBXSourcesBuildPhase section */ | ||
7F4811BD1C9BE3FE00252CB6 /* Sources */ = { | ||
isa = PBXSourcesBuildPhase; | ||
buildActionMask = 2147483647; | ||
files = ( | ||
7F4811C71C9BE3FE00252CB6 /* RSAEncryptor.m in Sources */, | ||
); | ||
runOnlyForDeploymentPostprocessing = 0; | ||
}; | ||
/* End PBXSourcesBuildPhase section */ | ||
|
||
/* Begin XCBuildConfiguration section */ | ||
7F4811C81C9BE3FE00252CB6 /* Debug */ = { | ||
isa = XCBuildConfiguration; | ||
buildSettings = { | ||
ALWAYS_SEARCH_USER_PATHS = NO; | ||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; | ||
CLANG_CXX_LIBRARY = "libc++"; | ||
CLANG_ENABLE_MODULES = YES; | ||
CLANG_ENABLE_OBJC_ARC = YES; | ||
CLANG_WARN_BOOL_CONVERSION = YES; | ||
CLANG_WARN_CONSTANT_CONVERSION = YES; | ||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; | ||
CLANG_WARN_EMPTY_BODY = YES; | ||
CLANG_WARN_ENUM_CONVERSION = YES; | ||
CLANG_WARN_INT_CONVERSION = YES; | ||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; | ||
CLANG_WARN_UNREACHABLE_CODE = YES; | ||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; | ||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; | ||
COPY_PHASE_STRIP = NO; | ||
DEBUG_INFORMATION_FORMAT = dwarf; | ||
ENABLE_STRICT_OBJC_MSGSEND = YES; | ||
ENABLE_TESTABILITY = YES; | ||
GCC_C_LANGUAGE_STANDARD = gnu99; | ||
GCC_DYNAMIC_NO_PIC = NO; | ||
GCC_NO_COMMON_BLOCKS = YES; | ||
GCC_OPTIMIZATION_LEVEL = 0; | ||
GCC_PREPROCESSOR_DEFINITIONS = ( | ||
"DEBUG=1", | ||
"$(inherited)", | ||
); | ||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES; | ||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; | ||
GCC_WARN_UNDECLARED_SELECTOR = YES; | ||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; | ||
GCC_WARN_UNUSED_FUNCTION = YES; | ||
GCC_WARN_UNUSED_VARIABLE = YES; | ||
IPHONEOS_DEPLOYMENT_TARGET = 9.2; | ||
MTL_ENABLE_DEBUG_INFO = YES; | ||
ONLY_ACTIVE_ARCH = YES; | ||
SDKROOT = iphoneos; | ||
}; | ||
name = Debug; | ||
}; | ||
7F4811C91C9BE3FE00252CB6 /* Release */ = { | ||
isa = XCBuildConfiguration; | ||
buildSettings = { | ||
ALWAYS_SEARCH_USER_PATHS = NO; | ||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; | ||
CLANG_CXX_LIBRARY = "libc++"; | ||
CLANG_ENABLE_MODULES = YES; | ||
CLANG_ENABLE_OBJC_ARC = YES; | ||
CLANG_WARN_BOOL_CONVERSION = YES; | ||
CLANG_WARN_CONSTANT_CONVERSION = YES; | ||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; | ||
CLANG_WARN_EMPTY_BODY = YES; | ||
CLANG_WARN_ENUM_CONVERSION = YES; | ||
CLANG_WARN_INT_CONVERSION = YES; | ||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; | ||
CLANG_WARN_UNREACHABLE_CODE = YES; | ||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; | ||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; | ||
COPY_PHASE_STRIP = NO; | ||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; | ||
ENABLE_NS_ASSERTIONS = NO; | ||
ENABLE_STRICT_OBJC_MSGSEND = YES; | ||
GCC_C_LANGUAGE_STANDARD = gnu99; | ||
GCC_NO_COMMON_BLOCKS = YES; | ||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES; | ||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; | ||
GCC_WARN_UNDECLARED_SELECTOR = YES; | ||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; | ||
GCC_WARN_UNUSED_FUNCTION = YES; | ||
GCC_WARN_UNUSED_VARIABLE = YES; | ||
IPHONEOS_DEPLOYMENT_TARGET = 9.2; | ||
MTL_ENABLE_DEBUG_INFO = NO; | ||
SDKROOT = iphoneos; | ||
VALIDATE_PRODUCT = YES; | ||
}; | ||
name = Release; | ||
}; | ||
7F4811CB1C9BE3FE00252CB6 /* Debug */ = { | ||
isa = XCBuildConfiguration; | ||
buildSettings = { | ||
OTHER_LDFLAGS = "-ObjC"; | ||
PRODUCT_NAME = "$(TARGET_NAME)"; | ||
SKIP_INSTALL = YES; | ||
}; | ||
name = Debug; | ||
}; | ||
7F4811CC1C9BE3FE00252CB6 /* Release */ = { | ||
isa = XCBuildConfiguration; | ||
buildSettings = { | ||
OTHER_LDFLAGS = "-ObjC"; | ||
PRODUCT_NAME = "$(TARGET_NAME)"; | ||
SKIP_INSTALL = YES; | ||
}; | ||
name = Release; | ||
}; | ||
/* End XCBuildConfiguration section */ | ||
|
||
/* Begin XCConfigurationList section */ | ||
7F4811BC1C9BE3FE00252CB6 /* Build configuration list for PBXProject "RSAEncryptor" */ = { | ||
isa = XCConfigurationList; | ||
buildConfigurations = ( | ||
7F4811C81C9BE3FE00252CB6 /* Debug */, | ||
7F4811C91C9BE3FE00252CB6 /* Release */, | ||
); | ||
defaultConfigurationIsVisible = 0; | ||
defaultConfigurationName = Release; | ||
}; | ||
7F4811CA1C9BE3FE00252CB6 /* Build configuration list for PBXNativeTarget "RSAEncryptor" */ = { | ||
isa = XCConfigurationList; | ||
buildConfigurations = ( | ||
7F4811CB1C9BE3FE00252CB6 /* Debug */, | ||
7F4811CC1C9BE3FE00252CB6 /* Release */, | ||
); | ||
defaultConfigurationIsVisible = 0; | ||
}; | ||
/* End XCConfigurationList section */ | ||
}; | ||
rootObject = 7F4811B91C9BE3FE00252CB6 /* Project object */; | ||
} |
7 changes: 7 additions & 0 deletions
7
RSAEncryptor.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// RSAEncryptor.h | ||
// RSAEncryptor | ||
// | ||
// Created by qianhongqiang on 16/3/18. | ||
// Copyright © 2016年 qianhongqiang. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface RSAEncryptor : NSObject | ||
|
||
/*These APIs uesd to encrypt/decrypt data/string by pulick/private string. | ||
Sometimes we need to encrypt issue with string keys which wo get from web sercives. | ||
The goverment doesn't provide api which is able to encrypt/decrypt issue without certificate. | ||
The APIs fudges certificates use the pramaters 'str'. | ||
下面的api直接使用公私钥的字符串进行RSA加密。由于官方没有直接提供对应的api,所以这里使用公私钥字符串来伪造证书进行加密。 | ||
*/ | ||
+ (NSString *)encryptString:(NSString *)str publicKey:(NSString *)pubKey; | ||
+ (NSData *)encryptData:(NSData *)data publicKey:(NSString *)pubKey; | ||
+ (NSString *)decryptString:(NSString *)str publicKey:(NSString *)pubKey; | ||
+ (NSData *)decryptData:(NSData *)data publicKey:(NSString *)pubKey; | ||
+ (NSString *)decryptString:(NSString *)str privateKey:(NSString *)privKey; | ||
+ (NSData *)decryptData:(NSData *)data privateKey:(NSString *)privKey; | ||
|
||
/*These APIs uesd to encrypt/decrypt data/string by pulick/private certificate | ||
The public key should be suffixal with .der and private key with .p12 | ||
The original code https://github.com/baight/RSAEncryptor/blob/master/RSAEncryptor.m . | ||
I found that the decrypt mothed was wrong when data's length is longer than 128(the accurate value depends on the length of the keys.When the length of keys is 2048,it is 2048/8=256) | ||
I modified the code to make it run correctly. | ||
使用公私钥文件进行RSA加密 | ||
代码来源 https://github.com/baight/RSAEncryptor/blob/master/RSAEncryptor.m ,之所以上传这个库,因为我发现原本的代码在解密时时错误的,它只在解密文件很小(小于秘钥长度/8)才能正常工作。我更改了代码,让它可以正常工作 | ||
*/ | ||
- (void)loadPublicKeyFromFile:(NSString*)derFilePath; | ||
- (void)loadPublicKeyFromData:(NSData*)derData; | ||
|
||
- (void)loadPrivateKeyFromFile:(NSString*)p12FilePath password:(NSString*)p12Password; | ||
- (void)loadPrivateKeyFromData:(NSData*)p12Data password:(NSString*)p12Password; | ||
|
||
- (NSString*)rsaEncryptString:(NSString*)string; | ||
- (NSData*)rsaEncryptData:(NSData*)data ; | ||
|
||
- (NSString*)rsaDecryptString:(NSString *)string; | ||
- (NSData*)rsaDecryptData:(NSData *)data; | ||
|
||
+ (void)setSharedInstance:(RSAEncryptor *)instance; | ||
+ (RSAEncryptor*)sharedInstance; | ||
|
||
@end |
Oops, something went wrong.