Giter VIP home page Giter VIP logo

base64's Introduction

swift workflow License: MIT Issues Releases

Base64 Additions for Objective-C on Mac OS X and iOS

LICENSING

The project is dual licensed

  • Public Domain
  • MIT

Use it under whichever of these two licensing options that are allowed in your country and you feel the most comfortable with.

Installation

IMPORTANT If you have access to Swift libraries, use the built-in Base64 functions. They are faster in most cases.

Installation: Swift Package Manager

In your Package.swift, add

import PackageDescription

let package = Package(
    name: "MyApp",
    targets: [],
    dependencies: [
        .Package(url: "https://github.com/ekscrypto/Base64.git", .upToNextMajor(from: "1.2.2"))
    ]
)

Installation: Cococapods

Add the following line to your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'Base64'
end

Usage: Objective-C

NSString *helloWorld = @"Hello World";
NSString *helloInBase64 = [helloWorld base64String];
NSString *helloDecoded = [NSString stringFromBase64String:helloInBase64];

Usage: Swift

NOT RECOMMENDED: If you have access to the built-in base64 functions offered by Swift, use them. They are much faster.

Using MF_Base64codec directly

let data = "Hello World".data(using: .utf8)!
let base64 = MF_Base64Codec.base64String(from: data) // SGVsbG8gV29ybGQ=
let querySafeBase64 = MF_Base64Codec.base64UrlEncodedString(fromBase64String: base64) // SGVsbG8gV29ybGQ

Using NSData objects

let data = "Hello World".data(using: .utf8)! as NSData
let base64 = data.base64String() // SGVsbG8gV29ybGQ=
let querySafeBase64 = data.base64UrlEncodedString() // SGVsbG8gV29ybGQ

Performance


  • Encoding: 5% slower than Swift's built-in Base64 encoding
  • Encoding: 4 to 5 times faster than using the equivalent SecTransform.
  • Encoding: 30% faster than https://github.com/l4u/NSData-Base64 (metric from 2012)
  • Decoding: 4 times slower than Swift's built-in Base64 decoding
  • Decoding: 5% faster than using the equivalent SecTransform.
  • Decoding: 5% faster than https://github.com/l4u/NSData-Base64 (metric from 2012)

Performance metrics are based on evaluation done in 2022 using macOS, Xcode 13.2.1 and Swift 5.5.2 on a 2.2 GHz 6-Core Intel Core i7 MacBook Pro.

Requirements


  • Compile with Automatic Reference Counting
  • Compatible with Mac OSX 10.9+ and iOS 4.0+

Implementation


base64's People

Contributors

ekscrypto avatar kevboh avatar lolgear avatar martiall avatar readmecritic avatar soheilbm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

base64's Issues

Pendatic bug report :)

The package is public domain, but you have "Copyright (c) 2012 Freshcode. All rights reserved." in the Base64/Base64/main.m file.

Can not decode python encoded string

Try to decode this for me please:

NSString *helloInBase64 = @"AwFjOHd6WJKLQ9YG6gRTw0t96a1vYHNxCGRJnLs0y7Pt6RnZp0pQqJ9v4/Ui0mjUPUFVJ4Aoz1BdCmTsEw8frgY8UbDPBURX40Xow147q6dxg++zNDC1VJ+QgC4zEr3jQs3W2BWuKzmZk3w77Dmc2j/2U8fAW/ubbWE9VgVEq7RigwqMdiZS5o6ilmyrfy+BFsbn5ivVAzQT/E7jJU8uLhaLFCzShuEF9ha0nlWfrjMs9jpFtSX5oZ1zhPEN3SaNVxF+y5OPkz9KEvb3RvvXUIgRvlqbG4vmmLEDCL/KEVis5uzn27hl4e6HUCbSzjKrMEVIhTUy0CC8eIc1Z1IHDf24/qgz2Orm2xgnu//h9M3uuUyqP6A5yiowkM4li3bNL19lGLxNuHdf80gk4VbjAVni7vTvd/brKVGEqh4Y3GvU1xGVJfumy0jnhq8dQfjHpUbRXvZUEXtLpx4E6qyfsfnlUAJJH/Ym4Mao8bPHJnq3Uy8uj2UzECViJ8qj1k3HU3mOMtNkmuNDlMA6WFiszzm6Qh70u6LMuYfD3f14sXgbFwbqduUurC3PAyiCGHYKsmNXr7SVQKxT4ndVjRSh4H94CXrXOQZpgcUVjl6LGtjjKVTAp72BOvkWFEwgm1o7LERPtZh77rsamEedTCjIPCQcWIXM5PxGYfIyH0pveiLv0Xd5QRTRSvgM5fbd0gYcPZCvstrOz8aVcxRta60a77x5NxoGEyshXlKSb9x9MILh0AwlYI8XnqGyEDLywGRk1bJAiWSdcGLk+dyOEBSejjW3aZrX8ee4fDM0/YZ3IWvgJw=="

If it works please tell me what didi you do?
And you sould get some funny encrypted charcters once when you decode.

No shared schemes

Carthage build stops.

*** Skipped building Base64 due to the error:
Dependency "Base64" has no shared framework schemes

Version 1.1.2

doubt

can I use this to encode images? if yes how fast is this compared to default NSDATA base64 conversion?

I am a bit confused about Base32

I added repository as submodule and dragged project to workspace.
I noticed that something was wrong with this project - Base64 Xcode group has pointed to Base32 folder on disk.
I suppose that it was done for prevention of collisions.
However, could you change Base64 group path to Base64 ( now it points to Base32 ).
Or maybe it is better to rename Base64 to Base32 ( or another appropriate name ) to prevent any collisions.

Thanks!

UPD:
I can not use Xcode project now, because it has this workaround. It doesn't compile at all :(

Decrypted NSData has an extra character at the end

When decrypted, the NSData has often (not sure when exactly this happen) an extra character at the end, always a 7.
What am I doing wrong?

NSString *str = [[self convertToString:args] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSData *decodedData = [self dataFromBase64String:paddedStr];

This is my code.

Public Domain - Base64-1.1.2.zip

Dear Creator

Would it be okay to use your work [Base64-1.1.2.zip] under Creative Commons CC0 v1.0 Universal License (CC0 v1.0)?

The Swiss law do not recognize a permanent relinquishment of Copyrights as the Public Domain provides for.

Thank you very much and kind regards
Philipp

Add Base64UrlEncoding

Well, If I am right, it would be necessary to add methods that convert string into base64UrlEncodedString.

it could be useful in JWT library yourkarma/JWT#8.

dataWithBase64String pads output with 0's in some cases

dataWithBase64String produces NSData padded with 0's in some cases

Test string:

+eeehDVjt0qAN/eWmVYiCA==

Convert to NSData:

OpenSSL's Base64: <f9e79e84 3563b74a 8037f796 99562208> length: 16
NSData+Base64: <f9e79e84 3563b74a 8037f796 99562208> length: 16

...as expected, but:

Base64: <f9e79e84 3563b74a 8037f796 99562208 0000> length: 18
                                             ^^^^

-[__NSCFString base64String]: unrecognized selector sent to instance

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString base64String]: unrecognized selector sent to instance 0x8295ef0'

Looks like iOS 6 isn't liking this very much.

The example app works great but when copying basically the same example into iOS it crashes. I'm installing an iOS5.1 simulator to test it, I'll let you know.

UPDATE: Same problem in iOS 5.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.