Skip to content

Instantly share code, notes, and snippets.

@lamnt9
lamnt9 / String+AES.swift
Created December 11, 2024 06:39 — forked from mtsd/String+AES.swift
AES encryption in Swift
import CommonCrypto
// MARK: AES128 暗号、復号化
public extension String {
func aesEncrypt(key: String, iv: String) -> String? {
guard
let data = self.data(using: .utf8),
let key = key.data(using: .utf8),
let iv = iv.data(using: .utf8),
@lamnt9
lamnt9 / String+AES.swift
Created December 11, 2024 06:39 — forked from mtsd/String+AES.swift
AES encryption in Swift
import CommonCrypto
// MARK: AES128 暗号、復号化
public extension String {
func aesEncrypt(key: String, iv: String) -> String? {
guard
let data = self.data(using: .utf8),
let key = key.data(using: .utf8),
let iv = iv.data(using: .utf8),
@lamnt9
lamnt9 / makePNGFromView.swift
Created August 19, 2024 03:31 — forked from ericdke/makePNGFromView.swift
Swift: create PNG from NSView
func makePNGFromView(view: NSView) {
var rep = view.bitmapImageRepForCachingDisplayInRect(view.bounds)!
view.cacheDisplayInRect(view.bounds, toBitmapImageRep: rep)
if let data = rep.representationUsingType(NSBitmapImageFileType.NSPNGFileType, properties: [:]) {
data.writeToFile("/xxx/image.png", atomically: false)
}
}