Minecraft-Console-Client/MinecraftClient/Protocol/ProfileKey/PrivateKey.cs
BruceChen a8bbb1ac76
Basic support for minecraft 1.19 (#2084)
* merge commit from milutinke
* chat signature & encrypted login
* Bug fix :EncryptionResponse format error below 1.18.2
* Implemented chat command signature
* Chat message parsing and verification for 1.19
* Add signature settings
* Update Simplified Chinese Translation
* Clear up comments
* Fix wrong variable naming
* Bug fix: SignatureV2 Processing
2022-08-15 17:55:44 +02:00

39 lines
1.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace MinecraftClient.Protocol.Keys
{
public class PrivateKey
{
public byte[] Key { get; set; }
private readonly RSA rsa;
public PrivateKey(string pemKey)
{
this.Key = KeyUtils.DecodePemKey(pemKey, "-----BEGIN RSA PRIVATE KEY-----", "-----END RSA PRIVATE KEY-----");
this.rsa = RSA.Create();
rsa.ImportPkcs8PrivateKey(this.Key, out _);
}
public byte[] SignData(byte[] data)
{
return rsa.SignData(data, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
}
public byte[] SignMessage(string message, string uuid, DateTimeOffset timestamp, ref byte[] salt)
{
string messageJson = "{\"text\":\"" + KeyUtils.EscapeString(message) + "\"}";
byte[] data = KeyUtils.GetSignatureData(messageJson, uuid, timestamp, ref salt);
return SignData(data);
}
}
}