Comments (5)
Also base64 decode
extension CipherProtocol {
public func decrypt(_ bytes: Bytes, key: Bytes? = nil) throws -> Bytes {
return try decrypt(bytes, key: key ?? defaultKey, iv: defaultIV)
}
public func decrypt(_ string: String, key: Bytes? = nil, encoding: CipherEncoding = .base64) throws -> String {
let bytes: Bytes
switch encoding {
case .hex:
var data = Bytes()
var gen = string.characters.makeIterator()
while let c1 = gen.next(), let c2 = gen.next() {
let s = String([c1, c2])
guard let d = Byte(s, radix: 16) else {
break
}
data.append(d)
}
bytes = data
case .base64:
bytes = string.base64Decoded
}
let d = try decrypt(bytes, key: key)
return d.string
}
}
extension String {
public var base64Decoded: Bytes {
guard let data = NSData(base64Encoded: self, options: []) else { return [] }
var bytes = Bytes(repeating: 0, count: data.length)
data.getBytes(&bytes, length: data.length)
return bytes
}
}```
from core.
We can't do this until Swift 4 because we can't add initializers to generic array extensions, let's revisit this at that point.
from core.
It should be able to work exactly the same way that base64Encoded
works.
bytes.hexEncoded.string
string.bytes.hexDecoded
from core.
Yup, we can add properties, just can't do the traditional convertible pattern we've been using w/ the initializer .... but actually, we might be able to do this w/ arrays at least in 3.1. It can't conform to a protocol, but the behavior could be there.
Follow up, I'm 82% sure we have this functionality already, might just be different names.
from core.
Yeah I think it's just the naming right now. Same issue we had with base64 where you can only go Bytes -> String
etc.
from core.
Related Issues (20)
- Data does not conform to ReflectionDecodable HOT 1
- Possible bug in Async.flatten HOT 1
- [Feature] Change Decodable.decodeProperty(forKey:) Parameter Type to AnyKeyPath
- LazyFuture should support throwing
- "Free" ReflectionDecodable conformance for CaseIterable enums HOT 1
- Replace `Collection<Future>.flatten` with `Future.reduce`? HOT 8
- custom Codable `init(from:)` method causing incorrect reflection HOT 3
- Process.execute on macOS leaves a background thread spinning at 100% HOT 2
- Does Core support Cocoapods? HOT 9
- Is `Future.map(on: worker)` intentionally synchronous? HOT 6
- Process.asyncExecute has threading issue
- Replace `Future.flatMap` with `Future.then`? HOT 2
- Set should conform to ReflectionDecodable HOT 1
- core doesn't compile on tvOS and WatchOS HOT 2
- NSError conformance to Debuggable breaks type casting HOT 4
- ReflectionKeyedDecoder.decode() is not returning the "truthy" value when the context is active
- 2 Warnings during linux build with 5.0.x swift HOT 4
- Reflection very slow and using a lot of memory HOT 2
- DirectoryConfig.workDir not working with Xcode 11 integration with SPM HOT 8
- threading issues
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from core.