Skip to content

Instantly share code, notes, and snippets.

@daveio
Created April 19, 2025 11:44
Show Gist options
  • Select an option

  • Save daveio/ea801cc84715a973a8be98df4923b7fa to your computer and use it in GitHub Desktop.

Select an option

Save daveio/ea801cc84715a973a8be98df4923b7fa to your computer and use it in GitHub Desktop.
const detectKeyType = (key: string): KeyType => {
if (!key.trim()) return null;
if (
key.includes("-----BEGIN PRIVATE KEY-----") ||
key.includes("-----BEGIN RSA PRIVATE KEY-----") ||
key.includes("-----BEGIN EC PRIVATE KEY-----")
) {
return "PKCS#8";
} else if (key.includes("-----BEGIN OPENSSH PRIVATE KEY-----")) {
return "SSH";
} else {
return "Unknown";
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment