Hi,
I'm trying to create a SshPublicKey object from a public key string that has been generated using the ssh-keygen command in a cmd. I get an exception that says "Error while decoding key. ---> System.InvalidOperationException: Data too long."
this is the code I'm using:
var stream = new MemoryStream();
var writer = new StreamWriter(stream);
writer.Write(publicKeyString);
writer.Flush();
stream.Position = 0;
return new SshPublicKey(stream);
The public key that was generated is in this format:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDJrQZgKrcqeRsSSpTR4J5w013Ax2ZThIWhIZrSravuRo3XojUxunwDVoTku3PvJGbcL8sxFfCHI70myCk/6S7TK2rwUAmQoEJxV+DGwldBpkRoPRHy8eK31CDLHbkPpCIYJzacoteXZQXztLSKnBDqyhvQ5ILSTlnsYgNrJxoyDPUumXoD3ZAi7ReSOqDOqxOwkT5Nr9I7u1AYv4mDx8kStnWYQBBVbdSNADJJMQ/YG85Rhe4hS3B5zt/8TB+w/EIvej9Fh6+qDTVbgt+J/JrL6TL+EFXP+mtJKVTVYo09Nk5BA30V16ect48CGmvas+NPyn4k/ZYNH4TJRbk4YzvR corp\mattias.andries@PF-MAndries1
However a public key that is in this format does seem to work:
---- BEGIN SSH2 PUBLIC KEY ----
Comment: ""
AAAAB3NzaC1yc2EAAAABJQAAAQEAg8+3TU/U8OSEocpEH/V1s4BvtjrHt1li5uH3
GBU4EzpC4cgVQUBXliWwQhVQcseSpwtBoK6n/WN+LRGqdBzILkl9ahFj1KXi9zW1
dMeSEIElU6R7Tb9wBBVFUng+U0fiYt47QmfiONgEXm70ZrrHXPKKnu/XG3PboCDI
7IzhWSzrbTGcFTj3c/ZkJVIZkiZnOzvMD0SWXEdkD0mKAuoYunBYucSILjYbnL/P
AaftEwZtu8/GdS4hWseNBM3fv8xDBF/7Z5CzNAlDTrGVaKQqThMTlKzxcalsmzvL
gwBvITPypX5VIzrVYAXPHirR0+tAhr+/wbcO23WP662N0GwIHw==
---- END SSH2 PUBLIC KEY ----
Any ideas on why the first key format gets the exception but the second key works fine?
Thanks.