private Task <string> Decrypt(AuthResult aResult) { var jweHeader = Jose.JWT.Headers(aResult.JweToken); if (!jweHeader.TryGetValue("alg", out var alg)) { throw new Exception("Required Element Missing (JWE.alg)"); } if (!jweHeader.TryGetValue("typ", out var typ)) { throw new Exception("Required Element Missing (JWE.typ)"); } if (!jweHeader.TryGetValue("enc", out var enc)) { throw new Exception("Required Element Missing (JWE.enc)"); } try { using var key = KeyStore.GetClientKey(); return(Task.FromResult(Jose.JWT.Decode(aResult.JweToken, key, JweAlgorithm.RSA_OAEP, JweEncryption.A256CBC_HS512))); } catch (Exception) { throw new Exception("The JWE Decode error"); } }
public void CheckClientSignature() { var clientKey = KeyStore.GetClientKey(); var clientWallet = BlockChainAddress.Deserialize("12K5LnVWKCu9QGyB39uGAgVSAfBs33PKS96HSL93"); var scriptBuilder = new ScriptBuilder(); var inputScript = scriptBuilder.New() .AddToStack(clientKey.GetSignature()) .AddToStack(clientKey.GetPublicKey()) .Build(); var outputScript = scriptBuilder.New() .AddOperation(OpCodes.OP_DUP) .AddOperation(OpCodes.OP_HASH160) .AddToStack(clientWallet.PublicKeyHash) .AddOperation(OpCodes.OP_EQUALVERIFY) .AddOperation(OpCodes.OP_CHECKSIG) .Build(); var serializedInputScript = inputScript.Serialize(); var serializedOutputScript = outputScript.Serialize(); var deserializedInputScript = Script.Deserialize(serializedInputScript); var deserializedOutputScript = Script.Deserialize(serializedOutputScript); var interpreter = new ScriptInterpreter(); bool isCorrect = interpreter.Check(deserializedInputScript, deserializedOutputScript); Assert.IsTrue(isCorrect); }
private Task <string> Sign(string data, string kid) { var extraHeaders = new Dictionary <string, object> { { "typ", "JOSE" }, { "kid", kid }, { "iat", DateTime.UtcNow }, { "cty", "JWE" } }; using var key = KeyStore.GetClientKey(); return(Task.FromResult(Jose.JWT.Encode(data, key, JwsAlgorithm.RS256, extraHeaders: extraHeaders))); }