Skip to content

Instantly share code, notes, and snippets.

@OrderAndCh4oS
Last active February 10, 2020 10:39
Show Gist options
  • Save OrderAndCh4oS/e845e6cb868852da137d69315e64726a to your computer and use it in GitHub Desktop.
Save OrderAndCh4oS/e845e6cb868852da137d69315e64726a to your computer and use it in GitHub Desktop.
function chunkPublicKey(key) {
const start = '-----BEGIN PUBLIC KEY-----';
const end = '-----END PUBLIC KEY-----';
const result = [];
try {
const arr = key.split('');
while(arr.length) {
result.push(arr.splice(0, 64).join(''));
}
} catch(e) {
console.log('Error chunking key', e);
}
return `${start}\n\n${result.join('\n')}\n\n${end}`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment