I have a TextInput Area inside pasted some example ssh key to validate whether it is valid or not. Is there any npm package or regular expression? Example SSH key
<TextArea
id={'public-key'}
labelText={_getPublicKeyLabel()}
required
aria-required="true"
invalid={sshKeyInput.keyTouched && !_isPublicKeyValid()}
invalidText={sshKeyInput.key.length > 0 ? 'please provide valid ssh key' : t('dashboard.ssh_key_modal.public_key_required')}
rows={6}
light
onChange={(ev) =>
setSshKeyInput({
...sshKeyInput,
key: ev.target.value,
keyTouched: true,
})
}
/>
Exxample ssh-rsa AAAAB3NXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
If I enter this ssh key into text area how can we check whether it is valid or not. Please share me your thoughts or ideas
The only thing that you can validate on the client-side is to make sure the string starts with ssh-rsa. The actual key itself contains arbitrary alphanumeric characters with no fixed patterns.
It is like a physical door key. Apart from the common structure like a key blade or a key head that makes you believe "oh that looks like some sort of key", you can't tell whether that key is real or forged until you actually insert the key into the keyhole (i.e. private key).
If I were you, I won't bother doing client-side validation on SSH key strings, because quite frankly, there isn't much you can do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With