Files
RSync-Studio/Scripts/old/license-keygen.swift
T
2026-10-19 14:11:01 +01:00

29 lines
1.4 KiB
Swift
Executable File

#!/usr/bin/env swift
import Foundation
import CryptoKit
let fm = FileManager.default
let home = fm.homeDirectoryForCurrentUser
let directory = home.appendingPathComponent("Library/Application Support/Rsync Studio Licensing", isDirectory: true)
let privateURL = directory.appendingPathComponent("license-private-key.txt")
let publicURL = directory.appendingPathComponent("license-public-key.txt")
try fm.createDirectory(at: directory, withIntermediateDirectories: true)
if fm.fileExists(atPath: privateURL.path) || fm.fileExists(atPath: publicURL.path) {
fputs("Refusing to overwrite an existing licensing keypair at \(directory.path)\n", stderr)
exit(1)
}
let privateKey = Curve25519.Signing.PrivateKey()
let privateText = privateKey.rawRepresentation.base64EncodedString()
let publicText = privateKey.publicKey.rawRepresentation.base64EncodedString()
try privateText.write(to: privateURL, atomically: true, encoding: .utf8)
try publicText.write(to: publicURL, atomically: true, encoding: .utf8)
try fm.setAttributes([.posixPermissions: 0o600], ofItemAtPath: privateURL.path)
try fm.setAttributes([.posixPermissions: 0o644], ofItemAtPath: publicURL.path)
print("Created Rsync Studio Ed25519 licensing keypair.")
print("PRIVATE (KEEP SECRET): \(privateURL.path)")
print("PUBLIC: \(publicURL.path)")
print("\nPublic key for RsyncStudioLicensePublicKey:\n\(publicText)")