@capgo/cli
Version:
A CLI to upload to capgo servers
51 lines (50 loc) • 2.79 kB
TypeScript
import { Buffer } from 'node:buffer';
export declare function generateSessionKey(key: string): {
sessionKey: Buffer;
ivSessionKey: string;
};
export declare function encryptSource(source: Buffer, sessionKey: Buffer, ivSessionKey: string): Buffer;
export declare function decryptSource(source: Buffer, ivSessionKey: string, key: string): Buffer;
/**
* Encrypt a checksum with V2 RSA (legacy: treats the digest argument as base64 bytes, not hex).
* Prefer encryptChecksumV3 for current plugin versions.
*/
export declare function encryptChecksum(checksum: string, key: string): string;
/** Encrypt a SHA-256 hex digest with V3 RSA; ciphertext is hex-encoded. */
export declare function encryptChecksumV3(checksum: string, key: string): string;
/** Decrypt a V2 bundle checksum ciphertext (canonical base64) to its plaintext digest string. */
export declare function decryptChecksum(checksum: string, key: string): string;
/** Decrypt a V3 bundle checksum ciphertext (hex) to its plaintext digest string. */
export declare function decryptChecksumV3(checksum: string, key: string): string;
/**
* Compare a computed SHA-256 hex digest with decrypted checksum plaintext from RSA.
* V2 plugins expose the digest as base64; V3 uses hex. Both encode the same 32 bytes.
*/
export declare function sha256DigestMatchesComputed(computedSha256Hex: string, decryptedPlaintext: string): boolean;
/**
* Decrypt a bundle checksum with V3 and V2 RSA encodings. Returns unique plaintext candidates.
*/
export declare function decryptChecksumPlaintexts(encryptedChecksum: string, key: string): string[];
/** Try V2 and V3 RSA checksum decryption and compare each plaintext digest to the zip SHA-256 hex. */
export declare function verifyDecryptedBundleChecksum(computedSha256Hex: string, encryptedChecksum: string, publicKey: string): {
matches: boolean;
decryptedPlaintexts: string[];
};
/** Format decrypted checksum plaintext for CLI mismatch errors (hex as-is, base64 with derived hex). */
export declare function formatDecryptedChecksumForError(decryptedPlaintext: string): string;
interface RSAKeys {
publicKey: string;
privateKey: string;
}
export declare function createRSA(): RSAKeys;
export declare function derivePublicKeyFromPrivate(privateKeyPem: string): string;
/**
* Calculate the key ID from a public key
* Shows the first 20 characters of base64-encoded key body for easy visual verification
* Note: First 12 characters (MIIBCgKCAQEA) are always the same for 2048-bit RSA PKCS#1 keys,
* but we show all of them so users can easily match with their key file
* @param publicKey - RSA public key in PEM format
* @returns 20-character key ID or empty string if key is invalid
*/
export declare function calcKeyId(publicKey: string): string;
export {};