|
1234567891011121314151617181920212223242526272829303132333435 |
- //
- // File.swift
- //
- //
- // Created by Michiel Carman on 4/2/24.
- //
-
- import Foundation
- import Vapor
- import Crypto
-
- enum CryptoError: Error{
- case badRequest
- }
-
- struct CustomCrypto{
- public static func DecryptString(input: String) throws -> String{
- let apikey = Environment.get("API_KEY")
- print(apikey)
- let base64Key = "rv0ywT7Ygwh01jP1dQWBP39ogjq5ladO+EoNUGcBVq0=" // Replace with your actual key
- guard let keyData = Data(base64Encoded: base64Key) else {
- fatalError("Invalid Base64 key data")
- }
- let data = Data(base64Encoded: input)
- let encryptionKey = SymmetricKey(data: keyData)
- let sealedBox = try! AES.GCM.SealedBox(combined: data!)
- let decryptedData = try! AES.GCM.open(sealedBox, using: encryptionKey)
- guard let decryptedString = String(data: decryptedData, encoding: .utf8) else{
- throw CryptoError.badRequest
- }
- return decryptedString
- }
- }
-
-
|