Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception: RsaUsingSha alg expects key to be of RSA type #216

Open
Lionberg opened this issue Jan 18, 2023 · 1 comment
Open

Exception: RsaUsingSha alg expects key to be of RSA type #216

Lionberg opened this issue Jan 18, 2023 · 1 comment

Comments

@Lionberg
Copy link

JWT.Encode method throws exception complaining on invalid key, but the key is RSA type and valid.

`

const string key = @"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDRsqElHKG158ZujNSLzDR9Btv/o2EWNO74b24jUpd3U2Am461rakorD0jm0rFEi5yqHDkPhSS+WW6pSY32w5eTuNTEGhGcoZFrnzHAEO6W4tBRqtS2UTA84zvA92DTHyDK+HKVmQW9JmA4uaPe1CEwVS4ZCGreviUXu66fl1iSUUcgrPV6K2E1TrpbIsWP1uHeZDOhtLHkT6ubrcgC1VW3QMaiC4uAjYxeWsGhhKdr4Wr2q3ywU1OmBlbQOJva29qrAVhykqv0CxBDuezIZbaeJKvQjyd4BAXnYDQwFcXfjSXCNPHFjSi9g7E5okx/E/eeS4bBQ35rzShoOwhb0a0VK5gZm7MODtXiYZX+ws7F1ioBCOzHVJhimkXWBvSNbvqQRApBL57zD19DUw7btfjqYx4lXJj/lYG+ON72O4tzCa5nvObmIgnYcWxypQYBFo6UZfYcAfSL4t4HGN5eyON7qPs4Woy3lzhJkKLVvHu/+W7PvEgAvQucPzh0pU4O+q8= hms\dmitryl@PRCD1DMITRY
";
string ssToken;
            MssGetJWTTokenRS512("{\r\n  \"extra\": \"param\",  \"alg\": \"RS512\",\r\n  \"typ\": \"JWT\"\r\n}",
                "{\r\n  \"sub\": \"1234567890\",\r\n  \"name\": \"Dmitry Lubenskiy\",\r\n  \"iat\": 1516239022\r\n}",
                key, out ssToken);
public void MssGetJWTTokenRS512(string ssHeaderJson, string ssPayloadJson, string ssKey, out string ssToken) {
	
	 Dictionary<string, object> hvalues = JsonConvert.DeserializeObject<Dictionary<string, object>>(ssHeaderJson);
            var header = hvalues;

            Dictionary<string, object> pvalues = JsonConvert.DeserializeObject<Dictionary<string, object>>(ssPayloadJson);
            var payload = pvalues;

            var key = Encoding.UTF8.GetBytes(ssKey);

            ssToken = JWT.Encode(payload, key, JwsAlgorithm.RS512, header);
        } 
@dvsekhvalnov
Copy link
Owner

Hi @Lionberg ,

  1. what are exception details?
  2. your string key ssh-rsa .... is not something library supports as a RSA key input. Please see https://github.com/dvsekhvalnov/jose-jwt#rs--and-ps--family for supported key types details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants