├── .DS_Store ├── .gitignore ├── CCPAESEncode.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── CCPAESEncode ├── .DS_Store ├── AES.gif ├── AESTool │ ├── CCPAESTool.h │ └── CCPAESTool.m ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── GTMBase64 │ ├── GTMBase64.h │ ├── GTMBase64.m │ ├── GTMDefines.h │ └── README.md ├── Info.plist ├── ViewController.h ├── ViewController.m └── main.m ├── CCPAESEncodeTests ├── CCPAESEncodeTests.m └── Info.plist ├── CCPAESEncodeUITests ├── CCPAESEncodeUITests.m └── Info.plist ├── LICENSE └── README.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iccpeng/CCPAESEncode/7b00995c36cc8d90b29a86a1528c13b32dd818ec/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | # CocoaPods 31 | # 32 | # We recommend against adding the Pods directory to your .gitignore. However 33 | # you should judge for yourself, the pros and cons are mentioned at: 34 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 35 | # 36 | # Pods/ 37 | 38 | # Carthage 39 | # 40 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 41 | # Carthage/Checkouts 42 | 43 | Carthage/Build 44 | 45 | # fastlane 46 | # 47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 48 | # screenshots whenever they are needed. 49 | # For more information about the recommended setup visit: 50 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 51 | 52 | fastlane/report.xml 53 | fastlane/screenshots 54 | 55 | #Code Injection 56 | # 57 | # After new code Injection tools there's a generated folder /iOSInjectionProject 58 | # https://github.com/johnno1962/injectionforxcode 59 | 60 | iOSInjectionProject/ 61 | -------------------------------------------------------------------------------- /CCPAESEncode.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 21372DB21D7FDDC00092D9E3 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 21372DB11D7FDDC00092D9E3 /* main.m */; }; 11 | 21372DB51D7FDDC00092D9E3 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 21372DB41D7FDDC00092D9E3 /* AppDelegate.m */; }; 12 | 21372DB81D7FDDC00092D9E3 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 21372DB71D7FDDC00092D9E3 /* ViewController.m */; }; 13 | 21372DBB1D7FDDC00092D9E3 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 21372DB91D7FDDC00092D9E3 /* Main.storyboard */; }; 14 | 21372DBD1D7FDDC00092D9E3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 21372DBC1D7FDDC00092D9E3 /* Assets.xcassets */; }; 15 | 21372DC01D7FDDC00092D9E3 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 21372DBE1D7FDDC00092D9E3 /* LaunchScreen.storyboard */; }; 16 | 21372DCB1D7FDDC00092D9E3 /* CCPAESEncodeTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 21372DCA1D7FDDC00092D9E3 /* CCPAESEncodeTests.m */; }; 17 | 21372DD61D7FDDC00092D9E3 /* CCPAESEncodeUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 21372DD51D7FDDC00092D9E3 /* CCPAESEncodeUITests.m */; }; 18 | 21372DEC1D7FDE410092D9E3 /* GTMBase64.m in Sources */ = {isa = PBXBuildFile; fileRef = 21372DE91D7FDE410092D9E3 /* GTMBase64.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; 19 | 21372DED1D7FDE410092D9E3 /* README.md in Sources */ = {isa = PBXBuildFile; fileRef = 21372DEB1D7FDE410092D9E3 /* README.md */; }; 20 | 21372DF41D7FE8890092D9E3 /* CCPAESTool.m in Sources */ = {isa = PBXBuildFile; fileRef = 21372DF31D7FE8890092D9E3 /* CCPAESTool.m */; }; 21 | 21372DF61D8003BA0092D9E3 /* AES.gif in Resources */ = {isa = PBXBuildFile; fileRef = 21372DF51D8003BA0092D9E3 /* AES.gif */; }; 22 | /* End PBXBuildFile section */ 23 | 24 | /* Begin PBXContainerItemProxy section */ 25 | 21372DC71D7FDDC00092D9E3 /* PBXContainerItemProxy */ = { 26 | isa = PBXContainerItemProxy; 27 | containerPortal = 21372DA51D7FDDC00092D9E3 /* Project object */; 28 | proxyType = 1; 29 | remoteGlobalIDString = 21372DAC1D7FDDC00092D9E3; 30 | remoteInfo = CCPAESEncode; 31 | }; 32 | 21372DD21D7FDDC00092D9E3 /* PBXContainerItemProxy */ = { 33 | isa = PBXContainerItemProxy; 34 | containerPortal = 21372DA51D7FDDC00092D9E3 /* Project object */; 35 | proxyType = 1; 36 | remoteGlobalIDString = 21372DAC1D7FDDC00092D9E3; 37 | remoteInfo = CCPAESEncode; 38 | }; 39 | /* End PBXContainerItemProxy section */ 40 | 41 | /* Begin PBXFileReference section */ 42 | 21372DAD1D7FDDC00092D9E3 /* CCPAESEncode.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CCPAESEncode.app; sourceTree = BUILT_PRODUCTS_DIR; }; 43 | 21372DB11D7FDDC00092D9E3 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 44 | 21372DB31D7FDDC00092D9E3 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 45 | 21372DB41D7FDDC00092D9E3 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 46 | 21372DB61D7FDDC00092D9E3 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 47 | 21372DB71D7FDDC00092D9E3 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 48 | 21372DBA1D7FDDC00092D9E3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 49 | 21372DBC1D7FDDC00092D9E3 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 50 | 21372DBF1D7FDDC00092D9E3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 51 | 21372DC11D7FDDC00092D9E3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 52 | 21372DC61D7FDDC00092D9E3 /* CCPAESEncodeTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CCPAESEncodeTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 53 | 21372DCA1D7FDDC00092D9E3 /* CCPAESEncodeTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CCPAESEncodeTests.m; sourceTree = ""; }; 54 | 21372DCC1D7FDDC00092D9E3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 55 | 21372DD11D7FDDC00092D9E3 /* CCPAESEncodeUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CCPAESEncodeUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 56 | 21372DD51D7FDDC00092D9E3 /* CCPAESEncodeUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CCPAESEncodeUITests.m; sourceTree = ""; }; 57 | 21372DD71D7FDDC00092D9E3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 58 | 21372DE81D7FDE410092D9E3 /* GTMBase64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GTMBase64.h; sourceTree = ""; }; 59 | 21372DE91D7FDE410092D9E3 /* GTMBase64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTMBase64.m; sourceTree = ""; }; 60 | 21372DEA1D7FDE410092D9E3 /* GTMDefines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GTMDefines.h; sourceTree = ""; }; 61 | 21372DEB1D7FDE410092D9E3 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 62 | 21372DF21D7FE8890092D9E3 /* CCPAESTool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPAESTool.h; sourceTree = ""; }; 63 | 21372DF31D7FE8890092D9E3 /* CCPAESTool.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCPAESTool.m; sourceTree = ""; }; 64 | 21372DF51D8003BA0092D9E3 /* AES.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = AES.gif; sourceTree = ""; }; 65 | /* End PBXFileReference section */ 66 | 67 | /* Begin PBXFrameworksBuildPhase section */ 68 | 21372DAA1D7FDDC00092D9E3 /* Frameworks */ = { 69 | isa = PBXFrameworksBuildPhase; 70 | buildActionMask = 2147483647; 71 | files = ( 72 | ); 73 | runOnlyForDeploymentPostprocessing = 0; 74 | }; 75 | 21372DC31D7FDDC00092D9E3 /* Frameworks */ = { 76 | isa = PBXFrameworksBuildPhase; 77 | buildActionMask = 2147483647; 78 | files = ( 79 | ); 80 | runOnlyForDeploymentPostprocessing = 0; 81 | }; 82 | 21372DCE1D7FDDC00092D9E3 /* Frameworks */ = { 83 | isa = PBXFrameworksBuildPhase; 84 | buildActionMask = 2147483647; 85 | files = ( 86 | ); 87 | runOnlyForDeploymentPostprocessing = 0; 88 | }; 89 | /* End PBXFrameworksBuildPhase section */ 90 | 91 | /* Begin PBXGroup section */ 92 | 21372DA41D7FDDC00092D9E3 = { 93 | isa = PBXGroup; 94 | children = ( 95 | 21372DAF1D7FDDC00092D9E3 /* CCPAESEncode */, 96 | 21372DC91D7FDDC00092D9E3 /* CCPAESEncodeTests */, 97 | 21372DD41D7FDDC00092D9E3 /* CCPAESEncodeUITests */, 98 | 21372DAE1D7FDDC00092D9E3 /* Products */, 99 | ); 100 | sourceTree = ""; 101 | }; 102 | 21372DAE1D7FDDC00092D9E3 /* Products */ = { 103 | isa = PBXGroup; 104 | children = ( 105 | 21372DAD1D7FDDC00092D9E3 /* CCPAESEncode.app */, 106 | 21372DC61D7FDDC00092D9E3 /* CCPAESEncodeTests.xctest */, 107 | 21372DD11D7FDDC00092D9E3 /* CCPAESEncodeUITests.xctest */, 108 | ); 109 | name = Products; 110 | sourceTree = ""; 111 | }; 112 | 21372DAF1D7FDDC00092D9E3 /* CCPAESEncode */ = { 113 | isa = PBXGroup; 114 | children = ( 115 | 21372DF51D8003BA0092D9E3 /* AES.gif */, 116 | 21372DE71D7FDE410092D9E3 /* GTMBase64 */, 117 | 21372DE31D7FDE300092D9E3 /* AESTool */, 118 | 21372DB31D7FDDC00092D9E3 /* AppDelegate.h */, 119 | 21372DB41D7FDDC00092D9E3 /* AppDelegate.m */, 120 | 21372DB61D7FDDC00092D9E3 /* ViewController.h */, 121 | 21372DB71D7FDDC00092D9E3 /* ViewController.m */, 122 | 21372DB91D7FDDC00092D9E3 /* Main.storyboard */, 123 | 21372DBC1D7FDDC00092D9E3 /* Assets.xcassets */, 124 | 21372DBE1D7FDDC00092D9E3 /* LaunchScreen.storyboard */, 125 | 21372DC11D7FDDC00092D9E3 /* Info.plist */, 126 | 21372DB01D7FDDC00092D9E3 /* Supporting Files */, 127 | ); 128 | path = CCPAESEncode; 129 | sourceTree = ""; 130 | }; 131 | 21372DB01D7FDDC00092D9E3 /* Supporting Files */ = { 132 | isa = PBXGroup; 133 | children = ( 134 | 21372DB11D7FDDC00092D9E3 /* main.m */, 135 | ); 136 | name = "Supporting Files"; 137 | sourceTree = ""; 138 | }; 139 | 21372DC91D7FDDC00092D9E3 /* CCPAESEncodeTests */ = { 140 | isa = PBXGroup; 141 | children = ( 142 | 21372DCA1D7FDDC00092D9E3 /* CCPAESEncodeTests.m */, 143 | 21372DCC1D7FDDC00092D9E3 /* Info.plist */, 144 | ); 145 | path = CCPAESEncodeTests; 146 | sourceTree = ""; 147 | }; 148 | 21372DD41D7FDDC00092D9E3 /* CCPAESEncodeUITests */ = { 149 | isa = PBXGroup; 150 | children = ( 151 | 21372DD51D7FDDC00092D9E3 /* CCPAESEncodeUITests.m */, 152 | 21372DD71D7FDDC00092D9E3 /* Info.plist */, 153 | ); 154 | path = CCPAESEncodeUITests; 155 | sourceTree = ""; 156 | }; 157 | 21372DE31D7FDE300092D9E3 /* AESTool */ = { 158 | isa = PBXGroup; 159 | children = ( 160 | 21372DF21D7FE8890092D9E3 /* CCPAESTool.h */, 161 | 21372DF31D7FE8890092D9E3 /* CCPAESTool.m */, 162 | ); 163 | path = AESTool; 164 | sourceTree = ""; 165 | }; 166 | 21372DE71D7FDE410092D9E3 /* GTMBase64 */ = { 167 | isa = PBXGroup; 168 | children = ( 169 | 21372DE81D7FDE410092D9E3 /* GTMBase64.h */, 170 | 21372DE91D7FDE410092D9E3 /* GTMBase64.m */, 171 | 21372DEA1D7FDE410092D9E3 /* GTMDefines.h */, 172 | 21372DEB1D7FDE410092D9E3 /* README.md */, 173 | ); 174 | path = GTMBase64; 175 | sourceTree = ""; 176 | }; 177 | /* End PBXGroup section */ 178 | 179 | /* Begin PBXNativeTarget section */ 180 | 21372DAC1D7FDDC00092D9E3 /* CCPAESEncode */ = { 181 | isa = PBXNativeTarget; 182 | buildConfigurationList = 21372DDA1D7FDDC00092D9E3 /* Build configuration list for PBXNativeTarget "CCPAESEncode" */; 183 | buildPhases = ( 184 | 21372DA91D7FDDC00092D9E3 /* Sources */, 185 | 21372DAA1D7FDDC00092D9E3 /* Frameworks */, 186 | 21372DAB1D7FDDC00092D9E3 /* Resources */, 187 | ); 188 | buildRules = ( 189 | ); 190 | dependencies = ( 191 | ); 192 | name = CCPAESEncode; 193 | productName = CCPAESEncode; 194 | productReference = 21372DAD1D7FDDC00092D9E3 /* CCPAESEncode.app */; 195 | productType = "com.apple.product-type.application"; 196 | }; 197 | 21372DC51D7FDDC00092D9E3 /* CCPAESEncodeTests */ = { 198 | isa = PBXNativeTarget; 199 | buildConfigurationList = 21372DDD1D7FDDC00092D9E3 /* Build configuration list for PBXNativeTarget "CCPAESEncodeTests" */; 200 | buildPhases = ( 201 | 21372DC21D7FDDC00092D9E3 /* Sources */, 202 | 21372DC31D7FDDC00092D9E3 /* Frameworks */, 203 | 21372DC41D7FDDC00092D9E3 /* Resources */, 204 | ); 205 | buildRules = ( 206 | ); 207 | dependencies = ( 208 | 21372DC81D7FDDC00092D9E3 /* PBXTargetDependency */, 209 | ); 210 | name = CCPAESEncodeTests; 211 | productName = CCPAESEncodeTests; 212 | productReference = 21372DC61D7FDDC00092D9E3 /* CCPAESEncodeTests.xctest */; 213 | productType = "com.apple.product-type.bundle.unit-test"; 214 | }; 215 | 21372DD01D7FDDC00092D9E3 /* CCPAESEncodeUITests */ = { 216 | isa = PBXNativeTarget; 217 | buildConfigurationList = 21372DE01D7FDDC00092D9E3 /* Build configuration list for PBXNativeTarget "CCPAESEncodeUITests" */; 218 | buildPhases = ( 219 | 21372DCD1D7FDDC00092D9E3 /* Sources */, 220 | 21372DCE1D7FDDC00092D9E3 /* Frameworks */, 221 | 21372DCF1D7FDDC00092D9E3 /* Resources */, 222 | ); 223 | buildRules = ( 224 | ); 225 | dependencies = ( 226 | 21372DD31D7FDDC00092D9E3 /* PBXTargetDependency */, 227 | ); 228 | name = CCPAESEncodeUITests; 229 | productName = CCPAESEncodeUITests; 230 | productReference = 21372DD11D7FDDC00092D9E3 /* CCPAESEncodeUITests.xctest */; 231 | productType = "com.apple.product-type.bundle.ui-testing"; 232 | }; 233 | /* End PBXNativeTarget section */ 234 | 235 | /* Begin PBXProject section */ 236 | 21372DA51D7FDDC00092D9E3 /* Project object */ = { 237 | isa = PBXProject; 238 | attributes = { 239 | LastUpgradeCheck = 0720; 240 | ORGANIZATIONNAME = CCP; 241 | TargetAttributes = { 242 | 21372DAC1D7FDDC00092D9E3 = { 243 | CreatedOnToolsVersion = 7.2; 244 | }; 245 | 21372DC51D7FDDC00092D9E3 = { 246 | CreatedOnToolsVersion = 7.2; 247 | TestTargetID = 21372DAC1D7FDDC00092D9E3; 248 | }; 249 | 21372DD01D7FDDC00092D9E3 = { 250 | CreatedOnToolsVersion = 7.2; 251 | TestTargetID = 21372DAC1D7FDDC00092D9E3; 252 | }; 253 | }; 254 | }; 255 | buildConfigurationList = 21372DA81D7FDDC00092D9E3 /* Build configuration list for PBXProject "CCPAESEncode" */; 256 | compatibilityVersion = "Xcode 3.2"; 257 | developmentRegion = English; 258 | hasScannedForEncodings = 0; 259 | knownRegions = ( 260 | en, 261 | Base, 262 | ); 263 | mainGroup = 21372DA41D7FDDC00092D9E3; 264 | productRefGroup = 21372DAE1D7FDDC00092D9E3 /* Products */; 265 | projectDirPath = ""; 266 | projectRoot = ""; 267 | targets = ( 268 | 21372DAC1D7FDDC00092D9E3 /* CCPAESEncode */, 269 | 21372DC51D7FDDC00092D9E3 /* CCPAESEncodeTests */, 270 | 21372DD01D7FDDC00092D9E3 /* CCPAESEncodeUITests */, 271 | ); 272 | }; 273 | /* End PBXProject section */ 274 | 275 | /* Begin PBXResourcesBuildPhase section */ 276 | 21372DAB1D7FDDC00092D9E3 /* Resources */ = { 277 | isa = PBXResourcesBuildPhase; 278 | buildActionMask = 2147483647; 279 | files = ( 280 | 21372DF61D8003BA0092D9E3 /* AES.gif in Resources */, 281 | 21372DC01D7FDDC00092D9E3 /* LaunchScreen.storyboard in Resources */, 282 | 21372DBD1D7FDDC00092D9E3 /* Assets.xcassets in Resources */, 283 | 21372DBB1D7FDDC00092D9E3 /* Main.storyboard in Resources */, 284 | ); 285 | runOnlyForDeploymentPostprocessing = 0; 286 | }; 287 | 21372DC41D7FDDC00092D9E3 /* Resources */ = { 288 | isa = PBXResourcesBuildPhase; 289 | buildActionMask = 2147483647; 290 | files = ( 291 | ); 292 | runOnlyForDeploymentPostprocessing = 0; 293 | }; 294 | 21372DCF1D7FDDC00092D9E3 /* Resources */ = { 295 | isa = PBXResourcesBuildPhase; 296 | buildActionMask = 2147483647; 297 | files = ( 298 | ); 299 | runOnlyForDeploymentPostprocessing = 0; 300 | }; 301 | /* End PBXResourcesBuildPhase section */ 302 | 303 | /* Begin PBXSourcesBuildPhase section */ 304 | 21372DA91D7FDDC00092D9E3 /* Sources */ = { 305 | isa = PBXSourcesBuildPhase; 306 | buildActionMask = 2147483647; 307 | files = ( 308 | 21372DED1D7FDE410092D9E3 /* README.md in Sources */, 309 | 21372DB81D7FDDC00092D9E3 /* ViewController.m in Sources */, 310 | 21372DEC1D7FDE410092D9E3 /* GTMBase64.m in Sources */, 311 | 21372DB51D7FDDC00092D9E3 /* AppDelegate.m in Sources */, 312 | 21372DF41D7FE8890092D9E3 /* CCPAESTool.m in Sources */, 313 | 21372DB21D7FDDC00092D9E3 /* main.m in Sources */, 314 | ); 315 | runOnlyForDeploymentPostprocessing = 0; 316 | }; 317 | 21372DC21D7FDDC00092D9E3 /* Sources */ = { 318 | isa = PBXSourcesBuildPhase; 319 | buildActionMask = 2147483647; 320 | files = ( 321 | 21372DCB1D7FDDC00092D9E3 /* CCPAESEncodeTests.m in Sources */, 322 | ); 323 | runOnlyForDeploymentPostprocessing = 0; 324 | }; 325 | 21372DCD1D7FDDC00092D9E3 /* Sources */ = { 326 | isa = PBXSourcesBuildPhase; 327 | buildActionMask = 2147483647; 328 | files = ( 329 | 21372DD61D7FDDC00092D9E3 /* CCPAESEncodeUITests.m in Sources */, 330 | ); 331 | runOnlyForDeploymentPostprocessing = 0; 332 | }; 333 | /* End PBXSourcesBuildPhase section */ 334 | 335 | /* Begin PBXTargetDependency section */ 336 | 21372DC81D7FDDC00092D9E3 /* PBXTargetDependency */ = { 337 | isa = PBXTargetDependency; 338 | target = 21372DAC1D7FDDC00092D9E3 /* CCPAESEncode */; 339 | targetProxy = 21372DC71D7FDDC00092D9E3 /* PBXContainerItemProxy */; 340 | }; 341 | 21372DD31D7FDDC00092D9E3 /* PBXTargetDependency */ = { 342 | isa = PBXTargetDependency; 343 | target = 21372DAC1D7FDDC00092D9E3 /* CCPAESEncode */; 344 | targetProxy = 21372DD21D7FDDC00092D9E3 /* PBXContainerItemProxy */; 345 | }; 346 | /* End PBXTargetDependency section */ 347 | 348 | /* Begin PBXVariantGroup section */ 349 | 21372DB91D7FDDC00092D9E3 /* Main.storyboard */ = { 350 | isa = PBXVariantGroup; 351 | children = ( 352 | 21372DBA1D7FDDC00092D9E3 /* Base */, 353 | ); 354 | name = Main.storyboard; 355 | sourceTree = ""; 356 | }; 357 | 21372DBE1D7FDDC00092D9E3 /* LaunchScreen.storyboard */ = { 358 | isa = PBXVariantGroup; 359 | children = ( 360 | 21372DBF1D7FDDC00092D9E3 /* Base */, 361 | ); 362 | name = LaunchScreen.storyboard; 363 | sourceTree = ""; 364 | }; 365 | /* End PBXVariantGroup section */ 366 | 367 | /* Begin XCBuildConfiguration section */ 368 | 21372DD81D7FDDC00092D9E3 /* Debug */ = { 369 | isa = XCBuildConfiguration; 370 | buildSettings = { 371 | ALWAYS_SEARCH_USER_PATHS = NO; 372 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 373 | CLANG_CXX_LIBRARY = "libc++"; 374 | CLANG_ENABLE_MODULES = YES; 375 | CLANG_ENABLE_OBJC_ARC = YES; 376 | CLANG_WARN_BOOL_CONVERSION = YES; 377 | CLANG_WARN_CONSTANT_CONVERSION = YES; 378 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 379 | CLANG_WARN_EMPTY_BODY = YES; 380 | CLANG_WARN_ENUM_CONVERSION = YES; 381 | CLANG_WARN_INT_CONVERSION = YES; 382 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 383 | CLANG_WARN_UNREACHABLE_CODE = YES; 384 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 385 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 386 | COPY_PHASE_STRIP = NO; 387 | DEBUG_INFORMATION_FORMAT = dwarf; 388 | ENABLE_STRICT_OBJC_MSGSEND = YES; 389 | ENABLE_TESTABILITY = YES; 390 | GCC_C_LANGUAGE_STANDARD = gnu99; 391 | GCC_DYNAMIC_NO_PIC = NO; 392 | GCC_NO_COMMON_BLOCKS = YES; 393 | GCC_OPTIMIZATION_LEVEL = 0; 394 | GCC_PREPROCESSOR_DEFINITIONS = ( 395 | "DEBUG=1", 396 | "$(inherited)", 397 | ); 398 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 399 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 400 | GCC_WARN_UNDECLARED_SELECTOR = YES; 401 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 402 | GCC_WARN_UNUSED_FUNCTION = YES; 403 | GCC_WARN_UNUSED_VARIABLE = YES; 404 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 405 | MTL_ENABLE_DEBUG_INFO = YES; 406 | ONLY_ACTIVE_ARCH = YES; 407 | SDKROOT = iphoneos; 408 | }; 409 | name = Debug; 410 | }; 411 | 21372DD91D7FDDC00092D9E3 /* Release */ = { 412 | isa = XCBuildConfiguration; 413 | buildSettings = { 414 | ALWAYS_SEARCH_USER_PATHS = NO; 415 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 416 | CLANG_CXX_LIBRARY = "libc++"; 417 | CLANG_ENABLE_MODULES = YES; 418 | CLANG_ENABLE_OBJC_ARC = YES; 419 | CLANG_WARN_BOOL_CONVERSION = YES; 420 | CLANG_WARN_CONSTANT_CONVERSION = YES; 421 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 422 | CLANG_WARN_EMPTY_BODY = YES; 423 | CLANG_WARN_ENUM_CONVERSION = YES; 424 | CLANG_WARN_INT_CONVERSION = YES; 425 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 426 | CLANG_WARN_UNREACHABLE_CODE = YES; 427 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 428 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 429 | COPY_PHASE_STRIP = NO; 430 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 431 | ENABLE_NS_ASSERTIONS = NO; 432 | ENABLE_STRICT_OBJC_MSGSEND = YES; 433 | GCC_C_LANGUAGE_STANDARD = gnu99; 434 | GCC_NO_COMMON_BLOCKS = YES; 435 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 436 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 437 | GCC_WARN_UNDECLARED_SELECTOR = YES; 438 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 439 | GCC_WARN_UNUSED_FUNCTION = YES; 440 | GCC_WARN_UNUSED_VARIABLE = YES; 441 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 442 | MTL_ENABLE_DEBUG_INFO = NO; 443 | SDKROOT = iphoneos; 444 | VALIDATE_PRODUCT = YES; 445 | }; 446 | name = Release; 447 | }; 448 | 21372DDB1D7FDDC00092D9E3 /* Debug */ = { 449 | isa = XCBuildConfiguration; 450 | buildSettings = { 451 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 452 | INFOPLIST_FILE = CCPAESEncode/Info.plist; 453 | IPHONEOS_DEPLOYMENT_TARGET = 9.1; 454 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 455 | PRODUCT_BUNDLE_IDENTIFIER = CCP.CCPAESEncode; 456 | PRODUCT_NAME = "$(TARGET_NAME)"; 457 | }; 458 | name = Debug; 459 | }; 460 | 21372DDC1D7FDDC00092D9E3 /* Release */ = { 461 | isa = XCBuildConfiguration; 462 | buildSettings = { 463 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 464 | INFOPLIST_FILE = CCPAESEncode/Info.plist; 465 | IPHONEOS_DEPLOYMENT_TARGET = 9.1; 466 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 467 | PRODUCT_BUNDLE_IDENTIFIER = CCP.CCPAESEncode; 468 | PRODUCT_NAME = "$(TARGET_NAME)"; 469 | }; 470 | name = Release; 471 | }; 472 | 21372DDE1D7FDDC00092D9E3 /* Debug */ = { 473 | isa = XCBuildConfiguration; 474 | buildSettings = { 475 | BUNDLE_LOADER = "$(TEST_HOST)"; 476 | INFOPLIST_FILE = CCPAESEncodeTests/Info.plist; 477 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 478 | PRODUCT_BUNDLE_IDENTIFIER = CCP.CCPAESEncodeTests; 479 | PRODUCT_NAME = "$(TARGET_NAME)"; 480 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CCPAESEncode.app/CCPAESEncode"; 481 | }; 482 | name = Debug; 483 | }; 484 | 21372DDF1D7FDDC00092D9E3 /* Release */ = { 485 | isa = XCBuildConfiguration; 486 | buildSettings = { 487 | BUNDLE_LOADER = "$(TEST_HOST)"; 488 | INFOPLIST_FILE = CCPAESEncodeTests/Info.plist; 489 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 490 | PRODUCT_BUNDLE_IDENTIFIER = CCP.CCPAESEncodeTests; 491 | PRODUCT_NAME = "$(TARGET_NAME)"; 492 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CCPAESEncode.app/CCPAESEncode"; 493 | }; 494 | name = Release; 495 | }; 496 | 21372DE11D7FDDC00092D9E3 /* Debug */ = { 497 | isa = XCBuildConfiguration; 498 | buildSettings = { 499 | INFOPLIST_FILE = CCPAESEncodeUITests/Info.plist; 500 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 501 | PRODUCT_BUNDLE_IDENTIFIER = CCP.CCPAESEncodeUITests; 502 | PRODUCT_NAME = "$(TARGET_NAME)"; 503 | TEST_TARGET_NAME = CCPAESEncode; 504 | USES_XCTRUNNER = YES; 505 | }; 506 | name = Debug; 507 | }; 508 | 21372DE21D7FDDC00092D9E3 /* Release */ = { 509 | isa = XCBuildConfiguration; 510 | buildSettings = { 511 | INFOPLIST_FILE = CCPAESEncodeUITests/Info.plist; 512 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 513 | PRODUCT_BUNDLE_IDENTIFIER = CCP.CCPAESEncodeUITests; 514 | PRODUCT_NAME = "$(TARGET_NAME)"; 515 | TEST_TARGET_NAME = CCPAESEncode; 516 | USES_XCTRUNNER = YES; 517 | }; 518 | name = Release; 519 | }; 520 | /* End XCBuildConfiguration section */ 521 | 522 | /* Begin XCConfigurationList section */ 523 | 21372DA81D7FDDC00092D9E3 /* Build configuration list for PBXProject "CCPAESEncode" */ = { 524 | isa = XCConfigurationList; 525 | buildConfigurations = ( 526 | 21372DD81D7FDDC00092D9E3 /* Debug */, 527 | 21372DD91D7FDDC00092D9E3 /* Release */, 528 | ); 529 | defaultConfigurationIsVisible = 0; 530 | defaultConfigurationName = Release; 531 | }; 532 | 21372DDA1D7FDDC00092D9E3 /* Build configuration list for PBXNativeTarget "CCPAESEncode" */ = { 533 | isa = XCConfigurationList; 534 | buildConfigurations = ( 535 | 21372DDB1D7FDDC00092D9E3 /* Debug */, 536 | 21372DDC1D7FDDC00092D9E3 /* Release */, 537 | ); 538 | defaultConfigurationIsVisible = 0; 539 | defaultConfigurationName = Release; 540 | }; 541 | 21372DDD1D7FDDC00092D9E3 /* Build configuration list for PBXNativeTarget "CCPAESEncodeTests" */ = { 542 | isa = XCConfigurationList; 543 | buildConfigurations = ( 544 | 21372DDE1D7FDDC00092D9E3 /* Debug */, 545 | 21372DDF1D7FDDC00092D9E3 /* Release */, 546 | ); 547 | defaultConfigurationIsVisible = 0; 548 | defaultConfigurationName = Release; 549 | }; 550 | 21372DE01D7FDDC00092D9E3 /* Build configuration list for PBXNativeTarget "CCPAESEncodeUITests" */ = { 551 | isa = XCConfigurationList; 552 | buildConfigurations = ( 553 | 21372DE11D7FDDC00092D9E3 /* Debug */, 554 | 21372DE21D7FDDC00092D9E3 /* Release */, 555 | ); 556 | defaultConfigurationIsVisible = 0; 557 | defaultConfigurationName = Release; 558 | }; 559 | /* End XCConfigurationList section */ 560 | }; 561 | rootObject = 21372DA51D7FDDC00092D9E3 /* Project object */; 562 | } 563 | -------------------------------------------------------------------------------- /CCPAESEncode.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CCPAESEncode/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iccpeng/CCPAESEncode/7b00995c36cc8d90b29a86a1528c13b32dd818ec/CCPAESEncode/.DS_Store -------------------------------------------------------------------------------- /CCPAESEncode/AES.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iccpeng/CCPAESEncode/7b00995c36cc8d90b29a86a1528c13b32dd818ec/CCPAESEncode/AES.gif -------------------------------------------------------------------------------- /CCPAESEncode/AESTool/CCPAESTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // CCPAESTool.h 3 | // CCPAESEncode 4 | // 5 | // Created by DR on 16/9/7. 6 | // Copyright © 2016年 CCP. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /** 12 | * AES 工具类 13 | */ 14 | 15 | @interface CCPAESTool : NSObject 16 | 17 | /************************************************************************ 18 | 函数名称 : + (NSString *)inputDictionary:(NSMutableDictionary *)dict andSecretKey:(NSString *)key; 19 | 函数描述 : 将传进来的字典 进行 AES 加密后转成json字符串 20 | 21 | 加密的过程: 字典 --> json字符串 --> base64加密后的字符串 --> AES加密后base64再加密 --> 输出加密后的字符串 22 | 23 | 输入参数 : base64String base64编码的字符串 ; key 密钥 24 | 返回参数 : (NSDictionary *)dic 字典 25 | ********************************************************************** 26 | */ 27 | + (NSString *)inputDictionary:(NSMutableDictionary *)dict andSecretKey:(NSString *)key; 28 | 29 | /************************************************************************ 30 | 函数名称 : + (NSDictionary *)inputBase64String:(NSString *)base64String andSecretKey:(NSString *)key; 31 | 函数描述 : 将传进来的base64编码的字符 进行 AES 解密后转成字典 32 | 33 | 解密的过程 : 与加密过程相反 34 | 35 | 输入参数 : base64String base64编码的字符串 ; key 密钥 36 | 返回参数 : (NSDictionary *)dic 字典 37 | ********************************************************************** 38 | */ 39 | + (NSDictionary *)inputBase64String:(NSString *)base64String andSecretKey:(NSString *)key; 40 | 41 | /************************************************************************ 42 | 函数名称 : + (NSString*)dictionaryToJson:(NSDictionary *)dic; 43 | 函数描述 : 将字典转换成字符串 44 | 输入参数 : (NSDictionary *)dic 字典 45 | 返回参数 : 字符串 46 | ********************************************************************** 47 | */ 48 | + (NSString*)dictionaryToJson:(NSDictionary *)dic; 49 | 50 | /************************************************************************ 51 | 函数名称 : + (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString; 52 | 函数描述 : 将json字符串转换成字典 53 | 输入参数 : (NSString *)jsonString Json格式的字符串 54 | 返回参数 : 字典 55 | ********************************************************************** 56 | */ 57 | + (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString; 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /CCPAESEncode/AESTool/CCPAESTool.m: -------------------------------------------------------------------------------- 1 | // 2 | // CCPAESTool.m 3 | // CCPAESEncode 4 | // 5 | // Created by CCP on 16/9/7. 6 | // Copyright © 2016年 CCP. All rights reserved. 7 | // 8 | 9 | #import "CCPAESTool.h" 10 | #import "GTMBase64.h" 11 | #import 12 | #import 13 | 14 | @implementation CCPAESTool 15 | 16 | + (NSString *)inputDictionary:(NSMutableDictionary *)dict andSecretKey:(NSString *)key{ 17 | 18 | NSString *jsonString = [CCPAESTool dictionaryToJson:dict]; 19 | 20 | NSString *jsonBase64Str = [GTMBase64 encodeBase64String:jsonString]; 21 | 22 | NSString *encryptStr = [CCPAESTool AES128Encrypt:jsonBase64Str andSecretKey:key]; 23 | 24 | return encryptStr; 25 | } 26 | 27 | + (NSDictionary *)inputBase64String:(NSString *)base64String andSecretKey:(NSString *)key { 28 | 29 | NSString * jsonString = [CCPAESTool AES128Decrypt:base64String andSecretKey:key]; 30 | 31 | NSDictionary *dict = [CCPAESTool dictionaryWithJsonString:jsonString]; 32 | 33 | return dict; 34 | 35 | } 36 | 37 | /** 38 | * AES 加密 解密 39 | */ 40 | 41 | +(NSString *)AES128Encrypt:(NSString *)plainText andSecretKey:(NSString *)secretKeys 42 | { 43 | char keyPtr[kCCKeySizeAES128+1]; 44 | memset(keyPtr, 0, sizeof(keyPtr)); 45 | [secretKeys getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding]; 46 | 47 | NSData* data = [plainText dataUsingEncoding:NSUTF8StringEncoding]; 48 | 49 | NSUInteger dataLength = [data length]; 50 | 51 | NSUInteger diff = kCCKeySizeAES128 - (dataLength % kCCKeySizeAES128); 52 | NSUInteger newSize = 0; 53 | 54 | if(diff > 0) 55 | { 56 | newSize = dataLength + diff; 57 | } 58 | 59 | char dataPtr[newSize]; 60 | memcpy(dataPtr, [data bytes], [data length]); 61 | for(int i = 0; i < diff; i++) 62 | { 63 | dataPtr[i + dataLength] = 0x0000; // 注意 No padding 64 | } 65 | 66 | size_t bufferSize = newSize + kCCBlockSizeAES128; 67 | void *buffer = malloc(bufferSize); 68 | memset(buffer, 0, bufferSize); 69 | 70 | size_t numBytesCrypted = 0; 71 | 72 | CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt, 73 | kCCAlgorithmAES128, 74 | kCCOptionECBMode, 75 | keyPtr, 76 | kCCKeySizeAES128, 77 | NULL,//这个参数iv是个固定值,通常直接使用密钥即可。大家一定要注视这个参数,如果安卓、服务端和iOS端不统一,那么加密结果就会不一样,解密可能能解出来,但是解密后在末尾会出现一些\0、\t之类的。(注: 这里使用NULL) 78 | dataPtr, 79 | sizeof(dataPtr), 80 | buffer, 81 | bufferSize, 82 | &numBytesCrypted); 83 | 84 | if (cryptStatus == kCCSuccess) { 85 | NSData *resultData = [NSData dataWithBytesNoCopy:buffer length:numBytesCrypted]; 86 | return [GTMBase64 encodeBase64Data:resultData]; 87 | } 88 | free(buffer); 89 | return nil; 90 | } 91 | 92 | 93 | + (NSString *)AES128Decrypt:(NSString *)encryptText andSecretKey:(NSString *)secretKeys 94 | { 95 | char keyPtr[kCCKeySizeAES128 + 1]; 96 | memset(keyPtr, 0, sizeof(keyPtr)); 97 | [secretKeys getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding]; 98 | 99 | NSData *data = [GTMBase64 decodeData:[encryptText dataUsingEncoding:NSUTF8StringEncoding]]; 100 | NSUInteger dataLength = [data length]; 101 | size_t bufferSize = dataLength + kCCBlockSizeAES128; 102 | void *buffer = malloc(bufferSize); 103 | 104 | size_t numBytesCrypted = 0; 105 | CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt, 106 | kCCAlgorithmAES128, 107 | kCCOptionECBMode, 108 | keyPtr, 109 | kCCBlockSizeAES128, 110 | NULL,//这个参数iv是个固定值,通常直接使用密钥即可。大家一定要注视这个参数,如果安卓、服务端和iOS端不统一,那么加密结果就会不一样,解密可能能解出来,但是解密后在末尾会出现一些\0、\t之类的。(注:这里使用NULL) 111 | [data bytes], 112 | dataLength, 113 | buffer, 114 | bufferSize, 115 | &numBytesCrypted); 116 | if (cryptStatus == kCCSuccess) { 117 | NSData *resultData = [NSData dataWithBytesNoCopy:buffer length:numBytesCrypted]; 118 | 119 | return [GTMBase64 decodeBase64Data:resultData]; 120 | } 121 | free(buffer); 122 | return nil; 123 | } 124 | 125 | 126 | + (NSString*)dictionaryToJson:(NSMutableDictionary *)dic { 127 | NSError *parseError = nil; 128 | 129 | NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError]; 130 | 131 | return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; 132 | 133 | } 134 | 135 | + (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString { 136 | 137 | if (jsonString == nil) { 138 | return nil; 139 | } 140 | 141 | NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; 142 | NSError *err; 143 | NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err]; 144 | 145 | if(err) { 146 | NSLog(@"json解析失败:%@",err); 147 | return nil; 148 | } 149 | 150 | return dic; 151 | 152 | } 153 | 154 | @end 155 | -------------------------------------------------------------------------------- /CCPAESEncode/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // CCPAESEncode 4 | // 5 | // Created by DR on 16/9/7. 6 | // Copyright © 2016年 CCP. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /CCPAESEncode/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // CCPAESEncode 4 | // 5 | // Created by DR on 16/9/7. 6 | // Copyright © 2016年 CCP. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /CCPAESEncode/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /CCPAESEncode/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /CCPAESEncode/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 26 | 33 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /CCPAESEncode/GTMBase64/GTMBase64.h: -------------------------------------------------------------------------------- 1 | // 2 | // GTMBase64.h 3 | // 4 | // Copyright 2006-2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not 7 | // use this file except in compliance with the License. You may obtain a copy 8 | // of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 14 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 15 | // License for the specific language governing permissions and limitations under 16 | // the License. 17 | // 18 | 19 | #import 20 | #import "GTMDefines.h" 21 | 22 | // GTMBase64 23 | // 24 | /// Helper for handling Base64 and WebSafeBase64 encodings 25 | // 26 | /// The webSafe methods use different character set and also the results aren't 27 | /// always padded to a multiple of 4 characters. This is done so the resulting 28 | /// data can be used in urls and url query arguments without needing any 29 | /// encoding. You must use the webSafe* methods together, the data does not 30 | /// interop with the RFC methods. 31 | // 32 | @interface GTMBase64 : NSObject 33 | 34 | // 35 | // Standard Base64 (RFC) handling 36 | // 37 | 38 | // encodeData: 39 | // 40 | /// Base64 encodes contents of the NSData object. 41 | // 42 | /// Returns: 43 | /// A new autoreleased NSData with the encoded payload. nil for any error. 44 | // 45 | +(NSData *)encodeData:(NSData *)data; 46 | 47 | // decodeData: 48 | // 49 | /// Base64 decodes contents of the NSData object. 50 | // 51 | /// Returns: 52 | /// A new autoreleased NSData with the decoded payload. nil for any error. 53 | // 54 | +(NSData *)decodeData:(NSData *)data; 55 | 56 | // encodeBytes:length: 57 | // 58 | /// Base64 encodes the data pointed at by |bytes|. 59 | // 60 | /// Returns: 61 | /// A new autoreleased NSData with the encoded payload. nil for any error. 62 | // 63 | +(NSData *)encodeBytes:(const void *)bytes length:(NSUInteger)length; 64 | 65 | // decodeBytes:length: 66 | // 67 | /// Base64 decodes the data pointed at by |bytes|. 68 | // 69 | /// Returns: 70 | /// A new autoreleased NSData with the encoded payload. nil for any error. 71 | // 72 | +(NSData *)decodeBytes:(const void *)bytes length:(NSUInteger)length; 73 | 74 | // stringByEncodingData: 75 | // 76 | /// Base64 encodes contents of the NSData object. 77 | // 78 | /// Returns: 79 | /// A new autoreleased NSString with the encoded payload. nil for any error. 80 | // 81 | +(NSString *)stringByEncodingData:(NSData *)data; 82 | 83 | // stringByEncodingBytes:length: 84 | // 85 | /// Base64 encodes the data pointed at by |bytes|. 86 | // 87 | /// Returns: 88 | /// A new autoreleased NSString with the encoded payload. nil for any error. 89 | // 90 | +(NSString *)stringByEncodingBytes:(const void *)bytes length:(NSUInteger)length; 91 | 92 | // decodeString: 93 | // 94 | /// Base64 decodes contents of the NSString. 95 | // 96 | /// Returns: 97 | /// A new autoreleased NSData with the decoded payload. nil for any error. 98 | // 99 | +(NSData *)decodeString:(NSString *)string; 100 | 101 | // 102 | // Modified Base64 encoding so the results can go onto urls. 103 | // 104 | // The changes are in the characters generated and also allows the result to 105 | // not be padded to a multiple of 4. 106 | // Must use the matching call to encode/decode, won't interop with the 107 | // RFC versions. 108 | // 109 | 110 | // webSafeEncodeData:padded: 111 | // 112 | /// WebSafe Base64 encodes contents of the NSData object. If |padded| is YES 113 | /// then padding characters are added so the result length is a multiple of 4. 114 | // 115 | /// Returns: 116 | /// A new autoreleased NSData with the encoded payload. nil for any error. 117 | // 118 | +(NSData *)webSafeEncodeData:(NSData *)data 119 | padded:(BOOL)padded; 120 | 121 | // webSafeDecodeData: 122 | // 123 | /// WebSafe Base64 decodes contents of the NSData object. 124 | // 125 | /// Returns: 126 | /// A new autoreleased NSData with the decoded payload. nil for any error. 127 | // 128 | +(NSData *)webSafeDecodeData:(NSData *)data; 129 | 130 | // webSafeEncodeBytes:length:padded: 131 | // 132 | /// WebSafe Base64 encodes the data pointed at by |bytes|. If |padded| is YES 133 | /// then padding characters are added so the result length is a multiple of 4. 134 | // 135 | /// Returns: 136 | /// A new autoreleased NSData with the encoded payload. nil for any error. 137 | // 138 | +(NSData *)webSafeEncodeBytes:(const void *)bytes 139 | length:(NSUInteger)length 140 | padded:(BOOL)padded; 141 | 142 | // webSafeDecodeBytes:length: 143 | // 144 | /// WebSafe Base64 decodes the data pointed at by |bytes|. 145 | // 146 | /// Returns: 147 | /// A new autoreleased NSData with the encoded payload. nil for any error. 148 | // 149 | +(NSData *)webSafeDecodeBytes:(const void *)bytes length:(NSUInteger)length; 150 | 151 | // stringByWebSafeEncodingData:padded: 152 | // 153 | /// WebSafe Base64 encodes contents of the NSData object. If |padded| is YES 154 | /// then padding characters are added so the result length is a multiple of 4. 155 | // 156 | /// Returns: 157 | /// A new autoreleased NSString with the encoded payload. nil for any error. 158 | // 159 | +(NSString *)stringByWebSafeEncodingData:(NSData *)data 160 | padded:(BOOL)padded; 161 | 162 | // stringByWebSafeEncodingBytes:length:padded: 163 | // 164 | /// WebSafe Base64 encodes the data pointed at by |bytes|. If |padded| is YES 165 | /// then padding characters are added so the result length is a multiple of 4. 166 | // 167 | /// Returns: 168 | /// A new autoreleased NSString with the encoded payload. nil for any error. 169 | // 170 | +(NSString *)stringByWebSafeEncodingBytes:(const void *)bytes 171 | length:(NSUInteger)length 172 | padded:(BOOL)padded; 173 | 174 | // webSafeDecodeString: 175 | // 176 | /// WebSafe Base64 decodes contents of the NSString. 177 | // 178 | /// Returns: 179 | /// A new autoreleased NSData with the decoded payload. nil for any error. 180 | // 181 | +(NSData *)webSafeDecodeString:(NSString *)string; 182 | 183 | 184 | 185 | #pragma mark - base64 186 | + (NSString*)md5_base64: (NSString *) inPutText; 187 | + (NSString*)encodeBase64String:(NSString *)input; 188 | + (NSString*)decodeBase64String:(NSString *)input; 189 | + (NSString*)encodeBase64Data:(NSData *)data; 190 | + (NSString*)decodeBase64Data:(NSData *)data; 191 | 192 | @end 193 | -------------------------------------------------------------------------------- /CCPAESEncode/GTMBase64/GTMBase64.m: -------------------------------------------------------------------------------- 1 | // 2 | // GTMBase64.m 3 | // 4 | // Copyright 2006-2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not 7 | // use this file except in compliance with the License. You may obtain a copy 8 | // of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 14 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 15 | // License for the specific language governing permissions and limitations under 16 | // the License. 17 | // 18 | 19 | #import "GTMBase64.h" 20 | #import "GTMDefines.h" 21 | #import 22 | 23 | static const char *kBase64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 24 | static const char *kWebSafeBase64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; 25 | static const char kBase64PaddingChar = '='; 26 | static const char kBase64InvalidChar = 99; 27 | 28 | static const char kBase64DecodeChars[] = { 29 | // This array was generated by the following code: 30 | // #include 31 | // #include 32 | // #include 33 | // main() 34 | // { 35 | // static const char Base64[] = 36 | // "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 37 | // char *pos; 38 | // int idx, i, j; 39 | // printf(" "); 40 | // for (i = 0; i < 255; i += 8) { 41 | // for (j = i; j < i + 8; j++) { 42 | // pos = strchr(Base64, j); 43 | // if ((pos == NULL) || (j == 0)) 44 | // idx = 99; 45 | // else 46 | // idx = pos - Base64; 47 | // if (idx == 99) 48 | // printf(" %2d, ", idx); 49 | // else 50 | // printf(" %2d/*%c*/,", idx, j); 51 | // } 52 | // printf("\n "); 53 | // } 54 | // } 55 | 99, 99, 99, 99, 99, 99, 99, 99, 56 | 99, 99, 99, 99, 99, 99, 99, 99, 57 | 99, 99, 99, 99, 99, 99, 99, 99, 58 | 99, 99, 99, 99, 99, 99, 99, 99, 59 | 99, 99, 99, 99, 99, 99, 99, 99, 60 | 99, 99, 99, 62/*+*/, 99, 99, 99, 63/*/ */, 61 | 52/*0*/, 53/*1*/, 54/*2*/, 55/*3*/, 56/*4*/, 57/*5*/, 58/*6*/, 59/*7*/, 62 | 60/*8*/, 61/*9*/, 99, 99, 99, 99, 99, 99, 63 | 99, 0/*A*/, 1/*B*/, 2/*C*/, 3/*D*/, 4/*E*/, 5/*F*/, 6/*G*/, 64 | 7/*H*/, 8/*I*/, 9/*J*/, 10/*K*/, 11/*L*/, 12/*M*/, 13/*N*/, 14/*O*/, 65 | 15/*P*/, 16/*Q*/, 17/*R*/, 18/*S*/, 19/*T*/, 20/*U*/, 21/*V*/, 22/*W*/, 66 | 23/*X*/, 24/*Y*/, 25/*Z*/, 99, 99, 99, 99, 99, 67 | 99, 26/*a*/, 27/*b*/, 28/*c*/, 29/*d*/, 30/*e*/, 31/*f*/, 32/*g*/, 68 | 33/*h*/, 34/*i*/, 35/*j*/, 36/*k*/, 37/*l*/, 38/*m*/, 39/*n*/, 40/*o*/, 69 | 41/*p*/, 42/*q*/, 43/*r*/, 44/*s*/, 45/*t*/, 46/*u*/, 47/*v*/, 48/*w*/, 70 | 49/*x*/, 50/*y*/, 51/*z*/, 99, 99, 99, 99, 99, 71 | 99, 99, 99, 99, 99, 99, 99, 99, 72 | 99, 99, 99, 99, 99, 99, 99, 99, 73 | 99, 99, 99, 99, 99, 99, 99, 99, 74 | 99, 99, 99, 99, 99, 99, 99, 99, 75 | 99, 99, 99, 99, 99, 99, 99, 99, 76 | 99, 99, 99, 99, 99, 99, 99, 99, 77 | 99, 99, 99, 99, 99, 99, 99, 99, 78 | 99, 99, 99, 99, 99, 99, 99, 99, 79 | 99, 99, 99, 99, 99, 99, 99, 99, 80 | 99, 99, 99, 99, 99, 99, 99, 99, 81 | 99, 99, 99, 99, 99, 99, 99, 99, 82 | 99, 99, 99, 99, 99, 99, 99, 99, 83 | 99, 99, 99, 99, 99, 99, 99, 99, 84 | 99, 99, 99, 99, 99, 99, 99, 99, 85 | 99, 99, 99, 99, 99, 99, 99, 99, 86 | 99, 99, 99, 99, 99, 99, 99, 99 87 | }; 88 | 89 | static const char kWebSafeBase64DecodeChars[] = { 90 | // This array was generated by the following code: 91 | // #include 92 | // #include 93 | // #include 94 | // main() 95 | // { 96 | // static const char Base64[] = 97 | // "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; 98 | // char *pos; 99 | // int idx, i, j; 100 | // printf(" "); 101 | // for (i = 0; i < 255; i += 8) { 102 | // for (j = i; j < i + 8; j++) { 103 | // pos = strchr(Base64, j); 104 | // if ((pos == NULL) || (j == 0)) 105 | // idx = 99; 106 | // else 107 | // idx = pos - Base64; 108 | // if (idx == 99) 109 | // printf(" %2d, ", idx); 110 | // else 111 | // printf(" %2d/*%c*/,", idx, j); 112 | // } 113 | // printf("\n "); 114 | // } 115 | // } 116 | 99, 99, 99, 99, 99, 99, 99, 99, 117 | 99, 99, 99, 99, 99, 99, 99, 99, 118 | 99, 99, 99, 99, 99, 99, 99, 99, 119 | 99, 99, 99, 99, 99, 99, 99, 99, 120 | 99, 99, 99, 99, 99, 99, 99, 99, 121 | 99, 99, 99, 99, 99, 62/*-*/, 99, 99, 122 | 52/*0*/, 53/*1*/, 54/*2*/, 55/*3*/, 56/*4*/, 57/*5*/, 58/*6*/, 59/*7*/, 123 | 60/*8*/, 61/*9*/, 99, 99, 99, 99, 99, 99, 124 | 99, 0/*A*/, 1/*B*/, 2/*C*/, 3/*D*/, 4/*E*/, 5/*F*/, 6/*G*/, 125 | 7/*H*/, 8/*I*/, 9/*J*/, 10/*K*/, 11/*L*/, 12/*M*/, 13/*N*/, 14/*O*/, 126 | 15/*P*/, 16/*Q*/, 17/*R*/, 18/*S*/, 19/*T*/, 20/*U*/, 21/*V*/, 22/*W*/, 127 | 23/*X*/, 24/*Y*/, 25/*Z*/, 99, 99, 99, 99, 63/*_*/, 128 | 99, 26/*a*/, 27/*b*/, 28/*c*/, 29/*d*/, 30/*e*/, 31/*f*/, 32/*g*/, 129 | 33/*h*/, 34/*i*/, 35/*j*/, 36/*k*/, 37/*l*/, 38/*m*/, 39/*n*/, 40/*o*/, 130 | 41/*p*/, 42/*q*/, 43/*r*/, 44/*s*/, 45/*t*/, 46/*u*/, 47/*v*/, 48/*w*/, 131 | 49/*x*/, 50/*y*/, 51/*z*/, 99, 99, 99, 99, 99, 132 | 99, 99, 99, 99, 99, 99, 99, 99, 133 | 99, 99, 99, 99, 99, 99, 99, 99, 134 | 99, 99, 99, 99, 99, 99, 99, 99, 135 | 99, 99, 99, 99, 99, 99, 99, 99, 136 | 99, 99, 99, 99, 99, 99, 99, 99, 137 | 99, 99, 99, 99, 99, 99, 99, 99, 138 | 99, 99, 99, 99, 99, 99, 99, 99, 139 | 99, 99, 99, 99, 99, 99, 99, 99, 140 | 99, 99, 99, 99, 99, 99, 99, 99, 141 | 99, 99, 99, 99, 99, 99, 99, 99, 142 | 99, 99, 99, 99, 99, 99, 99, 99, 143 | 99, 99, 99, 99, 99, 99, 99, 99, 144 | 99, 99, 99, 99, 99, 99, 99, 99, 145 | 99, 99, 99, 99, 99, 99, 99, 99, 146 | 99, 99, 99, 99, 99, 99, 99, 99, 147 | 99, 99, 99, 99, 99, 99, 99, 99 148 | }; 149 | 150 | 151 | // Tests a character to see if it's a whitespace character. 152 | // 153 | // Returns: 154 | // YES if the character is a whitespace character. 155 | // NO if the character is not a whitespace character. 156 | // 157 | GTM_INLINE BOOL IsSpace(unsigned char c) { 158 | // we use our own mapping here because we don't want anything w/ locale 159 | // support. 160 | static BOOL kSpaces[256] = { 161 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, // 0-9 162 | 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, // 10-19 163 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 20-29 164 | 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, // 30-39 165 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 40-49 166 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 50-59 167 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 60-69 168 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 70-79 169 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 80-89 170 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 90-99 171 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 100-109 172 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 110-119 173 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 120-129 174 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 130-139 175 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 140-149 176 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 150-159 177 | 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 160-169 178 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 170-179 179 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 180-189 180 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 190-199 181 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 200-209 182 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 210-219 183 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 220-229 184 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 230-239 185 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 240-249 186 | 0, 0, 0, 0, 0, 1, // 250-255 187 | }; 188 | return kSpaces[c]; 189 | } 190 | 191 | // Calculate how long the data will be once it's base64 encoded. 192 | // 193 | // Returns: 194 | // The guessed encoded length for a source length 195 | // 196 | GTM_INLINE NSUInteger CalcEncodedLength(NSUInteger srcLen, BOOL padded) { 197 | NSUInteger intermediate_result = 8 * srcLen + 5; 198 | NSUInteger len = intermediate_result / 6; 199 | if (padded) { 200 | len = ((len + 3) / 4) * 4; 201 | } 202 | return len; 203 | } 204 | 205 | // Tries to calculate how long the data will be once it's base64 decoded. 206 | // Unlike the above, this is always an upperbound, since the source data 207 | // could have spaces and might end with the padding characters on them. 208 | // 209 | // Returns: 210 | // The guessed decoded length for a source length 211 | // 212 | GTM_INLINE NSUInteger GuessDecodedLength(NSUInteger srcLen) { 213 | return (srcLen + 3) / 4 * 3; 214 | } 215 | 216 | 217 | @interface GTMBase64 (PrivateMethods) 218 | 219 | +(NSData *)baseEncode:(const void *)bytes 220 | length:(NSUInteger)length 221 | charset:(const char *)charset 222 | padded:(BOOL)padded; 223 | 224 | +(NSData *)baseDecode:(const void *)bytes 225 | length:(NSUInteger)length 226 | charset:(const char*)charset 227 | requirePadding:(BOOL)requirePadding; 228 | 229 | +(NSUInteger)baseEncode:(const char *)srcBytes 230 | srcLen:(NSUInteger)srcLen 231 | destBytes:(char *)destBytes 232 | destLen:(NSUInteger)destLen 233 | charset:(const char *)charset 234 | padded:(BOOL)padded; 235 | 236 | +(NSUInteger)baseDecode:(const char *)srcBytes 237 | srcLen:(NSUInteger)srcLen 238 | destBytes:(char *)destBytes 239 | destLen:(NSUInteger)destLen 240 | charset:(const char *)charset 241 | requirePadding:(BOOL)requirePadding; 242 | 243 | 244 | @end 245 | 246 | 247 | @implementation GTMBase64 248 | 249 | // 250 | // Standard Base64 (RFC) handling 251 | // 252 | 253 | +(NSData *)encodeData:(NSData *)data { 254 | return [self baseEncode:[data bytes] 255 | length:[data length] 256 | charset:kBase64EncodeChars 257 | padded:YES]; 258 | } 259 | 260 | +(NSData *)decodeData:(NSData *)data { 261 | return [self baseDecode:[data bytes] 262 | length:[data length] 263 | charset:kBase64DecodeChars 264 | requirePadding:YES]; 265 | } 266 | 267 | +(NSData *)encodeBytes:(const void *)bytes length:(NSUInteger)length { 268 | return [self baseEncode:bytes 269 | length:length 270 | charset:kBase64EncodeChars 271 | padded:YES]; 272 | } 273 | 274 | +(NSData *)decodeBytes:(const void *)bytes length:(NSUInteger)length { 275 | return [self baseDecode:bytes 276 | length:length 277 | charset:kBase64DecodeChars 278 | requirePadding:YES]; 279 | } 280 | 281 | +(NSString *)stringByEncodingData:(NSData *)data { 282 | NSString *result = nil; 283 | NSData *converted = [self baseEncode:[data bytes] 284 | length:[data length] 285 | charset:kBase64EncodeChars 286 | padded:YES]; 287 | if (converted) { 288 | result = [[[NSString alloc] initWithData:converted 289 | encoding:NSASCIIStringEncoding] autorelease]; 290 | } 291 | return result; 292 | } 293 | 294 | +(NSString *)stringByEncodingBytes:(const void *)bytes length:(NSUInteger)length { 295 | NSString *result = nil; 296 | NSData *converted = [self baseEncode:bytes 297 | length:length 298 | charset:kBase64EncodeChars 299 | padded:YES]; 300 | if (converted) { 301 | result = [[[NSString alloc] initWithData:converted 302 | encoding:NSASCIIStringEncoding] autorelease]; 303 | } 304 | return result; 305 | } 306 | 307 | +(NSData *)decodeString:(NSString *)string { 308 | NSData *result = nil; 309 | NSData *data = [string dataUsingEncoding:NSASCIIStringEncoding]; 310 | if (data) { 311 | result = [self baseDecode:[data bytes] 312 | length:[data length] 313 | charset:kBase64DecodeChars 314 | requirePadding:YES]; 315 | } 316 | return result; 317 | } 318 | 319 | // 320 | // Modified Base64 encoding so the results can go onto urls. 321 | // 322 | // The changes are in the characters generated and also the result isn't 323 | // padded to a multiple of 4. 324 | // Must use the matching call to encode/decode, won't interop with the 325 | // RFC versions. 326 | // 327 | 328 | +(NSData *)webSafeEncodeData:(NSData *)data 329 | padded:(BOOL)padded { 330 | return [self baseEncode:[data bytes] 331 | length:[data length] 332 | charset:kWebSafeBase64EncodeChars 333 | padded:padded]; 334 | } 335 | 336 | +(NSData *)webSafeDecodeData:(NSData *)data { 337 | return [self baseDecode:[data bytes] 338 | length:[data length] 339 | charset:kWebSafeBase64DecodeChars 340 | requirePadding:NO]; 341 | } 342 | 343 | +(NSData *)webSafeEncodeBytes:(const void *)bytes 344 | length:(NSUInteger)length 345 | padded:(BOOL)padded { 346 | return [self baseEncode:bytes 347 | length:length 348 | charset:kWebSafeBase64EncodeChars 349 | padded:padded]; 350 | } 351 | 352 | +(NSData *)webSafeDecodeBytes:(const void *)bytes length:(NSUInteger)length { 353 | return [self baseDecode:bytes 354 | length:length 355 | charset:kWebSafeBase64DecodeChars 356 | requirePadding:NO]; 357 | } 358 | 359 | +(NSString *)stringByWebSafeEncodingData:(NSData *)data 360 | padded:(BOOL)padded { 361 | NSString *result = nil; 362 | NSData *converted = [self baseEncode:[data bytes] 363 | length:[data length] 364 | charset:kWebSafeBase64EncodeChars 365 | padded:padded]; 366 | if (converted) { 367 | result = [[[NSString alloc] initWithData:converted 368 | encoding:NSASCIIStringEncoding] autorelease]; 369 | } 370 | return result; 371 | } 372 | 373 | +(NSString *)stringByWebSafeEncodingBytes:(const void *)bytes 374 | length:(NSUInteger)length 375 | padded:(BOOL)padded { 376 | NSString *result = nil; 377 | NSData *converted = [self baseEncode:bytes 378 | length:length 379 | charset:kWebSafeBase64EncodeChars 380 | padded:padded]; 381 | if (converted) { 382 | result = [[[NSString alloc] initWithData:converted 383 | encoding:NSASCIIStringEncoding] autorelease]; 384 | } 385 | return result; 386 | } 387 | 388 | +(NSData *)webSafeDecodeString:(NSString *)string { 389 | NSData *result = nil; 390 | NSData *data = [string dataUsingEncoding:NSASCIIStringEncoding]; 391 | if (data) { 392 | result = [self baseDecode:[data bytes] 393 | length:[data length] 394 | charset:kWebSafeBase64DecodeChars 395 | requirePadding:NO]; 396 | } 397 | return result; 398 | } 399 | 400 | #pragma mark - base64 401 | + (NSString *) md5_base64: (NSString *) inPutText 402 | { 403 | const char *cStr = [inPutText UTF8String]; 404 | unsigned char digest[16]; 405 | CC_MD5( cStr, strlen(cStr), digest ); 406 | 407 | NSData * base64 = [[NSData alloc]initWithBytes:digest length:16]; 408 | base64 = [GTMBase64 encodeData:base64]; 409 | 410 | NSString * output = [[NSString alloc] initWithData:base64 encoding:NSUTF8StringEncoding]; 411 | return output; 412 | } 413 | + (NSString*)encodeBase64String:(NSString * )input { 414 | NSData *data = [input dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]; 415 | data = [GTMBase64 encodeData:data]; 416 | NSString *base64String = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]; 417 | return base64String; 418 | } 419 | 420 | + (NSString*)decodeBase64String:(NSString * )input { 421 | NSData *data = [input dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]; 422 | data = [GTMBase64 decodeData:data]; 423 | NSString *base64String = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]; 424 | return base64String; 425 | } 426 | 427 | + (NSString*)encodeBase64Data:(NSData *)data { 428 | data = [GTMBase64 encodeData:data]; 429 | NSString *base64String = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]; 430 | return base64String; 431 | } 432 | 433 | + (NSString*)decodeBase64Data:(NSData *)data { 434 | data = [GTMBase64 decodeData:data]; 435 | NSString *base64String = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]; 436 | return base64String; 437 | } 438 | 439 | @end 440 | 441 | @implementation GTMBase64 (PrivateMethods) 442 | 443 | // 444 | // baseEncode:length:charset:padded: 445 | // 446 | // Does the common lifting of creating the dest NSData. it creates & sizes the 447 | // data for the results. |charset| is the characters to use for the encoding 448 | // of the data. |padding| controls if the encoded data should be padded to a 449 | // multiple of 4. 450 | // 451 | // Returns: 452 | // an autorelease NSData with the encoded data, nil if any error. 453 | // 454 | +(NSData *)baseEncode:(const void *)bytes 455 | length:(NSUInteger)length 456 | charset:(const char *)charset 457 | padded:(BOOL)padded { 458 | // how big could it be? 459 | NSUInteger maxLength = CalcEncodedLength(length, padded); 460 | // make space 461 | NSMutableData *result = [NSMutableData data]; 462 | [result setLength:maxLength]; 463 | // do it 464 | NSUInteger finalLength = [self baseEncode:bytes 465 | srcLen:length 466 | destBytes:[result mutableBytes] 467 | destLen:[result length] 468 | charset:charset 469 | padded:padded]; 470 | if (finalLength) { 471 | _GTMDevAssert(finalLength == maxLength, @"how did we calc the length wrong?"); 472 | } else { 473 | // shouldn't happen, this means we ran out of space 474 | result = nil; 475 | } 476 | return result; 477 | } 478 | 479 | // 480 | // baseDecode:length:charset:requirePadding: 481 | // 482 | // Does the common lifting of creating the dest NSData. it creates & sizes the 483 | // data for the results. |charset| is the characters to use for the decoding 484 | // of the data. 485 | // 486 | // Returns: 487 | // an autorelease NSData with the decoded data, nil if any error. 488 | // 489 | // 490 | +(NSData *)baseDecode:(const void *)bytes 491 | length:(NSUInteger)length 492 | charset:(const char *)charset 493 | requirePadding:(BOOL)requirePadding { 494 | // could try to calculate what it will end up as 495 | NSUInteger maxLength = GuessDecodedLength(length); 496 | // make space 497 | NSMutableData *result = [NSMutableData data]; 498 | [result setLength:maxLength]; 499 | // do it 500 | NSUInteger finalLength = [self baseDecode:bytes 501 | srcLen:length 502 | destBytes:[result mutableBytes] 503 | destLen:[result length] 504 | charset:charset 505 | requirePadding:requirePadding]; 506 | if (finalLength) { 507 | if (finalLength != maxLength) { 508 | // resize down to how big it was 509 | [result setLength:finalLength]; 510 | } 511 | } else { 512 | // either an error in the args, or we ran out of space 513 | result = nil; 514 | } 515 | return result; 516 | } 517 | 518 | // 519 | // baseEncode:srcLen:destBytes:destLen:charset:padded: 520 | // 521 | // Encodes the buffer into the larger. returns the length of the encoded 522 | // data, or zero for an error. 523 | // |charset| is the characters to use for the encoding 524 | // |padded| tells if the result should be padded to a multiple of 4. 525 | // 526 | // Returns: 527 | // the length of the encoded data. zero if any error. 528 | // 529 | +(NSUInteger)baseEncode:(const char *)srcBytes 530 | srcLen:(NSUInteger)srcLen 531 | destBytes:(char *)destBytes 532 | destLen:(NSUInteger)destLen 533 | charset:(const char *)charset 534 | padded:(BOOL)padded { 535 | if (!srcLen || !destLen || !srcBytes || !destBytes) { 536 | return 0; 537 | } 538 | 539 | char *curDest = destBytes; 540 | const unsigned char *curSrc = (const unsigned char *)(srcBytes); 541 | 542 | // Three bytes of data encodes to four characters of cyphertext. 543 | // So we can pump through three-byte chunks atomically. 544 | while (srcLen > 2) { 545 | // space? 546 | _GTMDevAssert(destLen >= 4, @"our calc for encoded length was wrong"); 547 | curDest[0] = charset[curSrc[0] >> 2]; 548 | curDest[1] = charset[((curSrc[0] & 0x03) << 4) + (curSrc[1] >> 4)]; 549 | curDest[2] = charset[((curSrc[1] & 0x0f) << 2) + (curSrc[2] >> 6)]; 550 | curDest[3] = charset[curSrc[2] & 0x3f]; 551 | 552 | curDest += 4; 553 | curSrc += 3; 554 | srcLen -= 3; 555 | destLen -= 4; 556 | } 557 | 558 | // now deal with the tail (<=2 bytes) 559 | switch (srcLen) { 560 | case 0: 561 | // Nothing left; nothing more to do. 562 | break; 563 | case 1: 564 | // One byte left: this encodes to two characters, and (optionally) 565 | // two pad characters to round out the four-character cypherblock. 566 | _GTMDevAssert(destLen >= 2, @"our calc for encoded length was wrong"); 567 | curDest[0] = charset[curSrc[0] >> 2]; 568 | curDest[1] = charset[(curSrc[0] & 0x03) << 4]; 569 | curDest += 2; 570 | destLen -= 2; 571 | if (padded) { 572 | _GTMDevAssert(destLen >= 2, @"our calc for encoded length was wrong"); 573 | curDest[0] = kBase64PaddingChar; 574 | curDest[1] = kBase64PaddingChar; 575 | curDest += 2; 576 | } 577 | break; 578 | case 2: 579 | // Two bytes left: this encodes to three characters, and (optionally) 580 | // one pad character to round out the four-character cypherblock. 581 | _GTMDevAssert(destLen >= 3, @"our calc for encoded length was wrong"); 582 | curDest[0] = charset[curSrc[0] >> 2]; 583 | curDest[1] = charset[((curSrc[0] & 0x03) << 4) + (curSrc[1] >> 4)]; 584 | curDest[2] = charset[(curSrc[1] & 0x0f) << 2]; 585 | curDest += 3; 586 | destLen -= 3; 587 | if (padded) { 588 | _GTMDevAssert(destLen >= 1, @"our calc for encoded length was wrong"); 589 | curDest[0] = kBase64PaddingChar; 590 | curDest += 1; 591 | } 592 | break; 593 | } 594 | // return the length 595 | return (curDest - destBytes); 596 | } 597 | 598 | // 599 | // baseDecode:srcLen:destBytes:destLen:charset:requirePadding: 600 | // 601 | // Decodes the buffer into the larger. returns the length of the decoded 602 | // data, or zero for an error. 603 | // |charset| is the character decoding buffer to use 604 | // 605 | // Returns: 606 | // the length of the encoded data. zero if any error. 607 | // 608 | +(NSUInteger)baseDecode:(const char *)srcBytes 609 | srcLen:(NSUInteger)srcLen 610 | destBytes:(char *)destBytes 611 | destLen:(NSUInteger)destLen 612 | charset:(const char *)charset 613 | requirePadding:(BOOL)requirePadding { 614 | if (!srcLen || !destLen || !srcBytes || !destBytes) { 615 | return 0; 616 | } 617 | 618 | int decode; 619 | NSUInteger destIndex = 0; 620 | int state = 0; 621 | char ch = 0; 622 | while (srcLen-- && (ch = *srcBytes++) != 0) { 623 | if (IsSpace(ch)) // Skip whitespace 624 | continue; 625 | 626 | if (ch == kBase64PaddingChar) 627 | break; 628 | 629 | decode = charset[(unsigned int)ch]; 630 | if (decode == kBase64InvalidChar) 631 | return 0; 632 | 633 | // Four cyphertext characters decode to three bytes. 634 | // Therefore we can be in one of four states. 635 | switch (state) { 636 | case 0: 637 | // We're at the beginning of a four-character cyphertext block. 638 | // This sets the high six bits of the first byte of the 639 | // plaintext block. 640 | _GTMDevAssert(destIndex < destLen, @"our calc for decoded length was wrong"); 641 | destBytes[destIndex] = decode << 2; 642 | state = 1; 643 | break; 644 | case 1: 645 | // We're one character into a four-character cyphertext block. 646 | // This sets the low two bits of the first plaintext byte, 647 | // and the high four bits of the second plaintext byte. 648 | _GTMDevAssert((destIndex+1) < destLen, @"our calc for decoded length was wrong"); 649 | destBytes[destIndex] |= decode >> 4; 650 | destBytes[destIndex+1] = (decode & 0x0f) << 4; 651 | destIndex++; 652 | state = 2; 653 | break; 654 | case 2: 655 | // We're two characters into a four-character cyphertext block. 656 | // This sets the low four bits of the second plaintext 657 | // byte, and the high two bits of the third plaintext byte. 658 | // However, if this is the end of data, and those two 659 | // bits are zero, it could be that those two bits are 660 | // leftovers from the encoding of data that had a length 661 | // of two mod three. 662 | _GTMDevAssert((destIndex+1) < destLen, @"our calc for decoded length was wrong"); 663 | destBytes[destIndex] |= decode >> 2; 664 | destBytes[destIndex+1] = (decode & 0x03) << 6; 665 | destIndex++; 666 | state = 3; 667 | break; 668 | case 3: 669 | // We're at the last character of a four-character cyphertext block. 670 | // This sets the low six bits of the third plaintext byte. 671 | _GTMDevAssert(destIndex < destLen, @"our calc for decoded length was wrong"); 672 | destBytes[destIndex] |= decode; 673 | destIndex++; 674 | state = 0; 675 | break; 676 | } 677 | } 678 | 679 | // We are done decoding Base-64 chars. Let's see if we ended 680 | // on a byte boundary, and/or with erroneous trailing characters. 681 | if (ch == kBase64PaddingChar) { // We got a pad char 682 | if ((state == 0) || (state == 1)) { 683 | return 0; // Invalid '=' in first or second position 684 | } 685 | if (srcLen == 0) { 686 | if (state == 2) { // We run out of input but we still need another '=' 687 | return 0; 688 | } 689 | // Otherwise, we are in state 3 and only need this '=' 690 | } else { 691 | if (state == 2) { // need another '=' 692 | while ((ch = *srcBytes++) && (srcLen-- > 0)) { 693 | if (!IsSpace(ch)) 694 | break; 695 | } 696 | if (ch != kBase64PaddingChar) { 697 | return 0; 698 | } 699 | } 700 | // state = 1 or 2, check if all remain padding is space 701 | while ((ch = *srcBytes++) && (srcLen-- > 0)) { 702 | if (!IsSpace(ch)) { 703 | return 0; 704 | } 705 | } 706 | } 707 | } else { 708 | // We ended by seeing the end of the string. 709 | 710 | if (requirePadding) { 711 | // If we require padding, then anything but state 0 is an error. 712 | if (state != 0) { 713 | return 0; 714 | } 715 | } else { 716 | // Make sure we have no partial bytes lying around. Note that we do not 717 | // require trailing '=', so states 2 and 3 are okay too. 718 | if (state == 1) { 719 | return 0; 720 | } 721 | } 722 | } 723 | 724 | // If then next piece of output was valid and got written to it means we got a 725 | // very carefully crafted input that appeared valid but contains some trailing 726 | // bits past the real length, so just toss the thing. 727 | if ((destIndex < destLen) && 728 | (destBytes[destIndex] != 0)) { 729 | return 0; 730 | } 731 | 732 | return destIndex; 733 | } 734 | 735 | 736 | @end 737 | -------------------------------------------------------------------------------- /CCPAESEncode/GTMBase64/GTMDefines.h: -------------------------------------------------------------------------------- 1 | // 2 | // GTMDefines.h 3 | // 4 | // Copyright 2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not 7 | // use this file except in compliance with the License. You may obtain a copy 8 | // of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 14 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 15 | // License for the specific language governing permissions and limitations under 16 | // the License. 17 | // 18 | 19 | // ============================================================================ 20 | 21 | #include 22 | 23 | // Not all MAC_OS_X_VERSION_10_X macros defined in past SDKs 24 | #ifndef MAC_OS_X_VERSION_10_5 25 | #define MAC_OS_X_VERSION_10_5 1050 26 | #endif 27 | #ifndef MAC_OS_X_VERSION_10_6 28 | #define MAC_OS_X_VERSION_10_6 1060 29 | #endif 30 | 31 | // ---------------------------------------------------------------------------- 32 | // CPP symbols that can be overridden in a prefix to control how the toolbox 33 | // is compiled. 34 | // ---------------------------------------------------------------------------- 35 | 36 | 37 | // GTMHTTPFetcher will support logging by default but only hook its input 38 | // stream support for logging when requested. You can control the inclusion of 39 | // the code by providing your own definitions for these w/in a prefix header. 40 | // 41 | #ifndef GTM_HTTPFETCHER_ENABLE_LOGGING 42 | #define GTM_HTTPFETCHER_ENABLE_LOGGING 1 43 | #endif // GTM_HTTPFETCHER_ENABLE_LOGGING 44 | #ifndef GTM_HTTPFETCHER_ENABLE_INPUTSTREAM_LOGGING 45 | #define GTM_HTTPFETCHER_ENABLE_INPUTSTREAM_LOGGING 0 46 | #endif // GTM_HTTPFETCHER_ENABLE_INPUTSTREAM_LOGGING 47 | 48 | // By setting the GTM_CONTAINERS_VALIDATION_FAILED_LOG and 49 | // GTM_CONTAINERS_VALIDATION_FAILED_ASSERT macros you can control what happens 50 | // when a validation fails. If you implement your own validators, you may want 51 | // to control their internals using the same macros for consistency. 52 | #ifndef GTM_CONTAINERS_VALIDATION_FAILED_ASSERT 53 | #define GTM_CONTAINERS_VALIDATION_FAILED_ASSERT 0 54 | #endif 55 | 56 | // Give ourselves a consistent way to do inlines. Apple's macros even use 57 | // a few different actual definitions, so we're based off of the foundation 58 | // one. 59 | #if !defined(GTM_INLINE) 60 | #if defined (__GNUC__) && (__GNUC__ == 4) 61 | #define GTM_INLINE static __inline__ __attribute__((always_inline)) 62 | #else 63 | #define GTM_INLINE static __inline__ 64 | #endif 65 | #endif 66 | 67 | // Give ourselves a consistent way of doing externs that links up nicely 68 | // when mixing objc and objc++ 69 | #if !defined (GTM_EXTERN) 70 | #if defined __cplusplus 71 | #define GTM_EXTERN extern "C" 72 | #else 73 | #define GTM_EXTERN extern 74 | #endif 75 | #endif 76 | 77 | // Give ourselves a consistent way of exporting things if we have visibility 78 | // set to hidden. 79 | #if !defined (GTM_EXPORT) 80 | #define GTM_EXPORT __attribute__((visibility("default"))) 81 | #endif 82 | 83 | // _GTMDevLog & _GTMDevAssert 84 | // 85 | // _GTMDevLog & _GTMDevAssert are meant to be a very lightweight shell for 86 | // developer level errors. This implementation simply macros to NSLog/NSAssert. 87 | // It is not intended to be a general logging/reporting system. 88 | // 89 | // Please see http://code.google.com/p/google-toolbox-for-mac/wiki/DevLogNAssert 90 | // for a little more background on the usage of these macros. 91 | // 92 | // _GTMDevLog log some error/problem in debug builds 93 | // _GTMDevAssert assert if conditon isn't met w/in a method/function 94 | // in all builds. 95 | // 96 | // To replace this system, just provide different macro definitions in your 97 | // prefix header. Remember, any implementation you provide *must* be thread 98 | // safe since this could be called by anything in what ever situtation it has 99 | // been placed in. 100 | // 101 | 102 | // We only define the simple macros if nothing else has defined this. 103 | #ifndef _GTMDevLog 104 | 105 | #ifdef DEBUG 106 | #define _GTMDevLog(...) NSLog(__VA_ARGS__) 107 | #else 108 | #define _GTMDevLog(...) do { } while (0) 109 | #endif 110 | 111 | #endif // _GTMDevLog 112 | 113 | // Declared here so that it can easily be used for logging tracking if 114 | // necessary. See GTMUnitTestDevLog.h for details. 115 | @class NSString; 116 | GTM_EXTERN void _GTMUnitTestDevLog(NSString *format, ...); 117 | 118 | #ifndef _GTMDevAssert 119 | // we directly invoke the NSAssert handler so we can pass on the varargs 120 | // (NSAssert doesn't have a macro we can use that takes varargs) 121 | #if !defined(NS_BLOCK_ASSERTIONS) 122 | #define _GTMDevAssert(condition, ...) \ 123 | do { \ 124 | if (!(condition)) { \ 125 | [[NSAssertionHandler currentHandler] \ 126 | handleFailureInFunction:[NSString stringWithUTF8String:__PRETTY_FUNCTION__] \ 127 | file:[NSString stringWithUTF8String:__FILE__] \ 128 | lineNumber:__LINE__ \ 129 | description:__VA_ARGS__]; \ 130 | } \ 131 | } while(0) 132 | #else // !defined(NS_BLOCK_ASSERTIONS) 133 | #define _GTMDevAssert(condition, ...) do { } while (0) 134 | #endif // !defined(NS_BLOCK_ASSERTIONS) 135 | 136 | #endif // _GTMDevAssert 137 | 138 | // _GTMCompileAssert 139 | // _GTMCompileAssert is an assert that is meant to fire at compile time if you 140 | // want to check things at compile instead of runtime. For example if you 141 | // want to check that a wchar is 4 bytes instead of 2 you would use 142 | // _GTMCompileAssert(sizeof(wchar_t) == 4, wchar_t_is_4_bytes_on_OS_X) 143 | // Note that the second "arg" is not in quotes, and must be a valid processor 144 | // symbol in it's own right (no spaces, punctuation etc). 145 | 146 | // Wrapping this in an #ifndef allows external groups to define their own 147 | // compile time assert scheme. 148 | #ifndef _GTMCompileAssert 149 | // We got this technique from here: 150 | // http://unixjunkie.blogspot.com/2007/10/better-compile-time-asserts_29.html 151 | 152 | #define _GTMCompileAssertSymbolInner(line, msg) _GTMCOMPILEASSERT ## line ## __ ## msg 153 | #define _GTMCompileAssertSymbol(line, msg) _GTMCompileAssertSymbolInner(line, msg) 154 | #define _GTMCompileAssert(test, msg) \ 155 | typedef char _GTMCompileAssertSymbol(__LINE__, msg) [ ((test) ? 1 : -1) ] 156 | #endif // _GTMCompileAssert 157 | 158 | // Macro to allow fast enumeration when building for 10.5 or later, and 159 | // reliance on NSEnumerator for 10.4. Remember, NSDictionary w/ FastEnumeration 160 | // does keys, so pick the right thing, nothing is done on the FastEnumeration 161 | // side to be sure you're getting what you wanted. 162 | #ifndef GTM_FOREACH_OBJECT 163 | #if defined(TARGET_OS_IPHONE) || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5) 164 | #define GTM_FOREACH_OBJECT(element, collection) \ 165 | for (element in collection) 166 | #define GTM_FOREACH_KEY(element, collection) \ 167 | for (element in collection) 168 | #else 169 | #define GTM_FOREACH_OBJECT(element, collection) \ 170 | for (NSEnumerator * _ ## element ## _enum = [collection objectEnumerator]; \ 171 | (element = [_ ## element ## _enum nextObject]) != nil; ) 172 | #define GTM_FOREACH_KEY(element, collection) \ 173 | for (NSEnumerator * _ ## element ## _enum = [collection keyEnumerator]; \ 174 | (element = [_ ## element ## _enum nextObject]) != nil; ) 175 | #endif 176 | #endif 177 | 178 | // ============================================================================ 179 | 180 | // ---------------------------------------------------------------------------- 181 | // CPP symbols defined based on the project settings so the GTM code has 182 | // simple things to test against w/o scattering the knowledge of project 183 | // setting through all the code. 184 | // ---------------------------------------------------------------------------- 185 | 186 | // Provide a single constant CPP symbol that all of GTM uses for ifdefing 187 | // iPhone code. 188 | #include 189 | #if TARGET_OS_IPHONE // iPhone SDK 190 | // For iPhone specific stuff 191 | #define GTM_IPHONE_SDK 1 192 | #if TARGET_IPHONE_SIMULATOR 193 | #define GTM_IPHONE_SIMULATOR 1 194 | #else 195 | #define GTM_IPHONE_DEVICE 1 196 | #endif // TARGET_IPHONE_SIMULATOR 197 | #else 198 | // For MacOS specific stuff 199 | #define GTM_MACOS_SDK 1 200 | #endif 201 | 202 | // Provide a symbol to include/exclude extra code for GC support. (This mainly 203 | // just controls the inclusion of finalize methods). 204 | #ifndef GTM_SUPPORT_GC 205 | #if GTM_IPHONE_SDK 206 | // iPhone never needs GC 207 | #define GTM_SUPPORT_GC 0 208 | #else 209 | // We can't find a symbol to tell if GC is supported/required, so best we 210 | // do on Mac targets is include it if we're on 10.5 or later. 211 | #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4 212 | #define GTM_SUPPORT_GC 0 213 | #else 214 | #define GTM_SUPPORT_GC 1 215 | #endif 216 | #endif 217 | #endif 218 | 219 | // To simplify support for 64bit (and Leopard in general), we provide the type 220 | // defines for non Leopard SDKs 221 | #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4 222 | // NSInteger/NSUInteger and Max/Mins 223 | #ifndef NSINTEGER_DEFINED 224 | #if __LP64__ || NS_BUILD_32_LIKE_64 225 | typedef long NSInteger; 226 | typedef unsigned long NSUInteger; 227 | #else 228 | typedef int NSInteger; 229 | typedef unsigned int NSUInteger; 230 | #endif 231 | #define NSIntegerMax LONG_MAX 232 | #define NSIntegerMin LONG_MIN 233 | #define NSUIntegerMax ULONG_MAX 234 | #define NSINTEGER_DEFINED 1 235 | #endif // NSINTEGER_DEFINED 236 | // CGFloat 237 | #ifndef CGFLOAT_DEFINED 238 | #if defined(__LP64__) && __LP64__ 239 | // This really is an untested path (64bit on Tiger?) 240 | typedef double CGFloat; 241 | #define CGFLOAT_MIN DBL_MIN 242 | #define CGFLOAT_MAX DBL_MAX 243 | #define CGFLOAT_IS_DOUBLE 1 244 | #else /* !defined(__LP64__) || !__LP64__ */ 245 | typedef float CGFloat; 246 | #define CGFLOAT_MIN FLT_MIN 247 | #define CGFLOAT_MAX FLT_MAX 248 | #define CGFLOAT_IS_DOUBLE 0 249 | #endif /* !defined(__LP64__) || !__LP64__ */ 250 | #define CGFLOAT_DEFINED 1 251 | #endif // CGFLOAT_DEFINED 252 | #endif // MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4 253 | -------------------------------------------------------------------------------- /CCPAESEncode/GTMBase64/README.md: -------------------------------------------------------------------------------- 1 | GTMBase64 2 | ========= 3 | 4 | Base64加解密 5 | 6 | 使用方法: 7 | 1)丢入ios项目。 8 | 【注意】开启ARC的同学注意 9 | 解决方法:-fno-objc-arc 10 | 11 | 2)在要使用GTMBase64的地方#import "GTMBase64.h"引入头文件 12 | 13 | 3)下面详细说明: 14 | 15 | 常用的方法,有下面几个: 16 | + (NSString*)md5_base64: (NSString *) inPutText; 17 | + (NSString*)encodeBase64String:(NSString *)input; 18 | + (NSString*)decodeBase64String:(NSString *)input; 19 | + (NSString*)encodeBase64Data:(NSData *)data; 20 | + (NSString*)decodeBase64Data:(NSData *)data; 21 | -------------------------------------------------------------------------------- /CCPAESEncode/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /CCPAESEncode/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // CCPAESEncode 4 | // 5 | // Created by DR on 16/9/7. 6 | // Copyright © 2016年 CCP. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /CCPAESEncode/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // CCPAESEncode 4 | // 5 | // Created by DR on 16/9/7. 6 | // Copyright © 2016年 CCP. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "CCPAESTool.h" 11 | 12 | /** 13 | * secrectKey 约定的16位的密钥,需要开发者之间商定。 14 | */ 15 | #define secrectKey @"1234567890123456" 16 | 17 | @interface ViewController () 18 | 19 | @property (nonatomic,strong) NSMutableDictionary *dict; 20 | 21 | @property (weak, nonatomic) IBOutlet UILabel *showLabel; 22 | @end 23 | 24 | @implementation ViewController 25 | 26 | - (void)viewDidLoad { 27 | [super viewDidLoad]; 28 | 29 | /** 30 | 31 | DEMO 下载地址 https://github.com/IMCCP 32 | 33 | 项目中用到AES加密,在这里整理成篇,供大家参考阅读,在使用该demo过程中,你可能会 34 | 遇到一些问题,首先你需要看一下下面的demo简介,看看该demo 是否适合你的项目。 35 | 36 | DEMO简介: 37 | 38 | 项目中的AES加解密主要用在网络请求过程中对上传的参数进行加密,对从后台服务器获取的数据进行解密。 39 | 40 | 整体的加密流程为: 41 | 42 | 加密的过程: 参数字典 --> json字符串 --> base64加密后的字符串 --> AES加密后base64再加密 --> 输出最终加密后的字符串; 43 | 44 | 解密的过程: 后台服务器获取加密的字符串 -->base64解密 --> AES解密后base64解密 --> json字符串 --> 数据字典;(与加密的过程相反) 45 | 46 | 网上对AES的详细介绍已经有很多,在这里不做赘述,如果你需要了解这些知识,度娘,GOOGLE 47 | 都是不错的选择. 48 | 49 | 在这里感谢这些 blog 的作者,让我在开发过程中少走了很多弯路: 50 | 51 | http://www.open-open.com/lib/view/open1453530956573.html 52 | 53 | http://blog.csdn.net/huangwenkui1990/article/details/48292865 54 | 55 | http://blog.csdn.net/j_akill/article/details/44079597 56 | 57 | https://wordpress-xiaominfc.rhcloud.com/?p=22#comment-12 58 | 59 | http://www.360doc.com/content/15/1012/10/20918780_505049436.shtml 60 | 61 | 公司后台为PHP,移动端有iOS与Android, 通过讨论我们选择AES的加密模式为 62 | AES128 + ECB + NoPadding (注意是否满足你的加密需求)。 63 | 64 | 为什么选择这种加密模式: 65 | 因为AES的加密规则 --> 原输入数据不够16字节的整数位时,就要补齐。因此就会有padding(填充模式),若使用不同的padding,那么加密出来的结果也会不一样。 66 | 如果采用PKCS7Padding或者PKCS5Padding这种加密方式,末端添加的数据可能不固定, 67 | 在解码后需要把末端多余的字符去掉,比较棘手。 68 | 如果不管补齐多少位,末端都是'\0',去掉的话比较容易操作。 69 | 70 | 最主要的是能够使得 iOS/Android/PHP 能够通信,也是加密过程中最难搞的地方,尤其需要开发者注意。(注意:别的加密模式也可以完成三者之间的通信,只是查找方法的时候 AES128 + ECB + NoPadding 这种加密方式使用的比较多,希望能有更好用的加密方式) 71 | 72 | 项目中用到了 google 的 base64 加解密库 GTMBase64,但是这个库已经有很多年没有更新 还是 MRC 开发模式,需要手动配置一下: 73 | 74 | 1,选择项目中的Targets,选中你所要操作的Target, 75 | 2,选Build Phases,在其中Complie Sources中选择需要ARC的文件双击, 76 | 并在输入框中输入 -fno-objc-arc 77 | 78 | 项目中遇到的一些坑,在项目中都已经注释出来,写的比较清楚,如果该 demo 帮助了您, 79 | 也希望能给个 star 鼓励一下,如果在使用中您有任何问题,可以在 github issue,我会尽自己能力给您答复 。 80 | */ 81 | 82 | self.dict = [NSMutableDictionary dictionary]; 83 | self.dict[@"HELLO"] = @"WORLD"; 84 | self.dict[@"GIT"] = @"HUB"; 85 | self.dict[@"https"] = @"https://github.com/IMCCP"; 86 | } 87 | 88 | //加密 89 | - (IBAction)clickEncodeBtn:(UIButton *)sender { 90 | 91 | NSString *AESString = [CCPAESTool inputDictionary:self.dict andSecretKey:secrectKey]; 92 | self.showLabel.text = AESString; 93 | 94 | } 95 | 96 | //解密 97 | - (IBAction)clickDecodeBtn:(UIButton *)sender { 98 | 99 | //上面加密的结果 100 | NSString *AESString = @"yNgE5k1LAo7jfWk4oLqQv2uuzOcnC+qKZC0d/69BcPy0NjpSARLfyziuoOe34ZIaVPo7V6Duz7w/SE2Y9jXVIIWbqJoMCWjnTTdnB9n/omo0ZZd7wlVeg8/Qq6nUdiLg7SAM7a5ulatguSWh/S1E+Ni1mEjHZwyUsptU0jeeLno="; 101 | //解密 102 | NSDictionary *dict = [CCPAESTool inputBase64String:AESString andSecretKey:secrectKey]; 103 | 104 | NSString *jsonString = [CCPAESTool dictionaryToJson:dict]; 105 | 106 | self.showLabel.text = jsonString; 107 | 108 | } 109 | 110 | @end 111 | -------------------------------------------------------------------------------- /CCPAESEncode/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // CCPAESEncode 4 | // 5 | // Created by DR on 16/9/7. 6 | // Copyright © 2016年 CCP. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /CCPAESEncodeTests/CCPAESEncodeTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // CCPAESEncodeTests.m 3 | // CCPAESEncodeTests 4 | // 5 | // Created by DR on 16/9/7. 6 | // Copyright © 2016年 CCP. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CCPAESEncodeTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation CCPAESEncodeTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /CCPAESEncodeTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /CCPAESEncodeUITests/CCPAESEncodeUITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // CCPAESEncodeUITests.m 3 | // CCPAESEncodeUITests 4 | // 5 | // Created by DR on 16/9/7. 6 | // Copyright © 2016年 CCP. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CCPAESEncodeUITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation CCPAESEncodeUITests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | 22 | // In UI tests it is usually best to stop immediately when a failure occurs. 23 | self.continueAfterFailure = NO; 24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 25 | [[[XCUIApplication alloc] init] launch]; 26 | 27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 28 | } 29 | 30 | - (void)tearDown { 31 | // Put teardown code here. This method is called after the invocation of each test method in the class. 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testExample { 36 | // Use recording to get started writing UI tests. 37 | // Use XCTAssert and related functions to verify your tests produce the correct results. 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /CCPAESEncodeUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CCPAESEncode 2 | 3 | AES加密(后台服务器为PHP) 4 | 5 | ## DEMO GIF 6 | 7 | ![Image text](https://github.com/IMCCP/CCPAESEncode/blob/master/CCPAESEncode/AES.gif) 8 | 9 | ## DEMO 简介 10 | ``` 11 | 最近用到AES加密,在这里整理成篇,供大家参考阅读,在使用该demo过程中,首先你需要看一下demo简 12 | 13 | 介,查看是否适合你的项目。 14 | 15 | 本DEMO AES加密流程为: 16 | 17 | 加密的过程: 参数字典 --> json字符串 --> base64加密后的字符串 --> AES加密后base64再加密 --> 输出最终加密后的字符串; 18 | 19 | 解密的过程: 20 | 21 | 获取加密的字符串 -->base64解密 --> AES解密后base64解密 --> json字符串 --> 数据字典;(与加密的过程相反) 22 | 23 | 网上对AES的详细介绍已经有很多,在这里不做赘述,如果你需要了解这些知识,度娘,google 去吧. 24 | ``` 25 | 26 | 在这里感谢这些 blog 的作者,让我在开发过程中少走了很多弯路: 27 | 28 | [http://www.open-open.com/lib/view/open1453530956573.html](http://www.open-open.com/lib/view/open1453530956573.html) 29 | 30 | [http://blog.csdn.net/huangwenkui1990/article/details/48292865](http://blog.csdn.net/huangwenkui1990/article/details/48292865) 31 | 32 | [http://blog.csdn.net/j_akill/article/details/44079597](http://blog.csdn.net/j_akill/article/details/44079597) 33 | 34 | [https://wordpress-xiaominfc.rhcloud.com/?p=22#comment-12](https://wordpress-xiaominfc.rhcloud.com/?p=22#comment-12) 35 | 36 | [http://www.360doc.com/content/15/1012/10/20918780_505049436.shtml](http://www.360doc.com/content/15/1012/10/20918780_505049436.shtml) 37 | 38 | ``` 39 | AES的加密规则 : 原输入数据不够16字节的整数位时,就要补齐。因此就会有padding(填充模式),若使用不同的padding,那么加密 40 | 41 | 出来的结果也会不一样。 42 | 43 | demo 中采用末尾补0 的填充方式(一定注意要保证安卓,服务端(PHP),还有iOS端一致,尤其需要开发者注意)。 44 | 45 | demo中用到了 google 的 base64 加解密库 GTMBase64,但是这个库已经有很多年没有更新 还是 MRC 开发模式,需要手动配置一下: 46 | 47 | 1.选择项目中的Targets,选中你所要操作的Target, 48 | 49 | 2.选Build Phases,在其中Complie Sources中选择需要ARC的文件双击,并在输入框中输入 -fno-objc-arc 50 | ``` 51 | 52 | ## DEMO 使用示例 53 | ``` 54 | //加密 55 | 56 | - (IBAction)clickEncodeBtn:(UIButton *)sender { 57 | 58 | NSMutableDictionary *dict = [NSMutableDictionary dictionary]; 59 | 60 | dict[@"HELLO"] = @"WORLD"; 61 | 62 | dict[@"GIT"] = @"HUB"; 63 | 64 | dict[@"https"] = @"github.com/IMCCP"; 65 | 66 | NSString *AESString = [CCPAESTool inputDictionary:self.dict andSecretKey:secrectKey]; 67 | 68 | self.showLabel.text = AESString; 69 | 70 | } 71 | ``` 72 | ``` 73 | //解密 74 | 75 | - (IBAction)clickDecodeBtn:(UIButton *)sender { 76 | 77 | //上面加密的结果 78 | NSString *AESString = @"yNgE5k1LAo7jfWk4oLqQv5YHxhBSOG0g6SjdFJoatZ2oTDL+jv1TpL7KWVcbMTH85kQCEFX9KWbsgegrwZ3JgrQ99I70Fd 79 | 80 | LKjSieKe7rfTz1qmbL9gBoe8GJz3TeqmIs7252agKLSDofW8J3mK8y1F4Y3tdnMGsWO9DZLhS/1v0="; 81 | 82 | //解密 83 | 84 | NSDictionary *dict = [CCPAESTool inputBase64String:AESString andSecretKey:secrectKey]; 85 | 86 | NSString *jsonString = [CCPAESTool dictionaryToJson:dict]; 87 | 88 | self.showLabel.text = jsonString; 89 | 90 | } 91 | ``` 92 | 93 | 如果在使用中您有任何问题,可以在 github issues,我会尽自己能力给您答复 。 94 | 95 | 96 | 97 | --------------------------------------------------------------------------------