             throw KeychainManagerError.add(statusCode)
         }
     }
-
-    public func getGenericPasswordForService(_ service: String) throws -> String {
+    
+    public func replaceGenericPassword(_ password: Data?, forService service: String) throws {
+        var query = queryForGenericPassword(by: service)
+
+        try delete(query)
+
+        guard let password = password else {
+            return
+        }
+
+        query = try updatedQuery(query, withPassword: password)
+
+        let statusCode = SecItemAdd(query as CFDictionary, nil)
+
+        guard statusCode == errSecSuccess else {
+            throw KeychainManagerError.add(statusCode)
+        }
+    }
+
+    public func getGenericPasswordForServiceAsData(_ service: String) throws -> Data {
         var query = queryForGenericPassword(by: service)
 
         query[kSecReturnData as String] = kCFBooleanTrue

            throw KeychainManagerError.copy(statusCode)
        }

        guard let passwordData = result as? Data, let password = String(data: passwordData, encoding: String.Encoding.utf8) else {
            throw KeychainManagerError.unknownResult
        }



        return query
    }
    
    private func updatedQuery(_ query: Query, withPassword password: Data) throws -> Query {
        var query = query

        query[kSecValueData as String] = password as NSObject?
        query[kSecAttrAccessible as String] = accessibility

        return query
    }

    private func updatedQuery(_ query: Query, withPassword password: String) throws -> Query {
        guard let value = password.data(using: String.Encoding.utf8) else {
            throw KeychainManagerError.add(errSecDecode)
        }

        return try updatedQuery(query, withPassword: value)
    }
    
    func delete(_ query: Query) throws {
        let statusCode = SecItemDelete(query as CFDictionary)

