CommonBase64Tools.swift 772 B

1234567891011121314151617181920212223242526272829
  1. //
  2. // CommonBase64Tools.swift
  3. // xingchuangke
  4. //
  5. // Created by Virgil on 2019/5/6.
  6. // Copyright © 2019 Virgil. All rights reserved.
  7. //
  8. import UIKit
  9. class CommonBase64Tools: NSObject {
  10. class func base64Encoding(str: String) -> String {
  11. let pData = str.data(using: .utf8)
  12. let b64 = pData!.base64EncodedString()
  13. return b64
  14. }
  15. class func base64DecodingToString(encodedString: String) -> String {
  16. let decodedData = Data(base64Encoded: encodedString)
  17. let decodedString = String(data: decodedData!, encoding: .utf8)!
  18. return decodedString
  19. }
  20. class func base64DecodingToData(encodedString: String) -> Data {
  21. let decodedData = Data(base64Encoded: encodedString)
  22. return decodedData!
  23. }
  24. }