일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
- IOS
- 신도림
- 스마트폰
- LG유플러스
- 페이백
- 포켓몬 GO
- 앱스토어
- simulator
- afterdelay
- error
- 얻는법
- 샘플
- GCD
- Example
- 아이폰7
- setting
- loop
- 공략
- Xcode
- swift3
- Bitcode
- push
- swift
- UIView
- 보라카이
- Check
- 해몽
- 신도림 테크노마트
- UITableView
- 포켓볼
- Today
- Total
도래울
cryptoSwift encrypt decrypt aes/ecb/pkcs7 본문
import CryptoSwift
let encryptKey = "ket"
let iv = "iv"
let ret = try! "password".aesEncrypt(encryptKey, iv: iv)
print("암호화 결과 : \(ret)")
let decrypt = try! ret.aesDecrypt(encryptKey, iv: iv)
print("복호화 결과 : \(decrypt)")
extension String {
func aesEncrypt(key: String, iv: String) throws -> String{
let data = self.dataUsingEncoding(NSUTF8StringEncoding)
let enc = try AES(key: key, iv: iv, blockMode:.ECB, padding: PKCS7()).encrypt(data!.arrayOfBytes())
let encData = NSData(bytes: enc, length: Int(enc.count))
let base64String: String = encData.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0));
let result = String(base64String)
return result
}
func aesDecrypt(key: String, iv: String) throws -> String {
let data = NSData(base64EncodedString: self, options: NSDataBase64DecodingOptions(rawValue: 0))
let dec = try AES(key: key, iv: iv, blockMode: .ECB, padding: PKCS7()).decrypt(data!.arrayOfBytes())
let decData = NSData(bytes: dec, length: Int(dec.count))
let result = NSString(data: decData, encoding: NSUTF8StringEncoding)
return String(result!)
}
}
'개발 > iOS' 카테고리의 다른 글
APNS 토큰 방식 (0) | 2016.11.25 |
---|---|
Xcode 8 주석 단축키 동작 안될때 (0) | 2016.11.24 |
ios bitcode error (0) | 2016.11.16 |
The executable was signed with invalid entitlements 에러 (0) | 2016.11.10 |
Changing navigation bar color in Swift (0) | 2016.11.09 |