Я пытаюсь зашифровать строку, используя библиотеку Jose-JWT с jweencryption.a128cbc_hs256
она зашифровала строку, но не удалась в декоде.using Jose;
using System.Text;
public class MyProgram {
public byte[] Digest() {
string semkey =
"dc5f7ad6cb89f1254696932d40d19ac079c14e8b3113351e48f5d6cf21263f4f";
int len = semkey.Length / 2;
byte[] val = new byte[len];
for (int i = 0; i < len; i++) {
int index = i * 2;
string hexByte = semkey.Substring(index, 2);
val = Convert.ToByte(hexByte, 16);
}
return val;
}
public string Encrypt(string input) {
byte[] key = Digest();
// Set the payload
byte[] payload = Encoding.UTF8.GetBytes(input);
// With this line:
string encrypted = JWT.Encode(payload, key, JweAlgorithm.A256KW,
JweEncryption.A128CBC_HS256);
string ptext = JWT.Decode(encrypted, key, JweAlgorithm.A256KW,
JweEncryption.A128CBC_HS256);
return encrypted;
}
public static void Main() {
MyModel model =
new { Email = "mail@mail.com", Phone = "987373721", Amt = 1000 };
string data = JsonSerializer.Serialize(model);
MyProgram p = new MyProgram();
string enc_token = p.Encrypt(data);
}
}
< /code>
, когда попробуйте JWT.Decode It, показывающий зашифрованную строку. < /p>
Что не так в моем коде. Пожалуйста, предложите.
Спасибо всем, кто сможет мне помочь. < /p>
Подробнее здесь: https://stackoverflow.com/questions/797 ... in-c-sharp