private static byte[] CreateSnPublicKeyBlob(BlobHeader header, RsaPubKey rsa, byte[] pubKeyData) { var snPubKey = new SnPublicKeyBlob() { SigAlgId = AlgorithmId.RsaSign, HashAlgId = AlgorithmId.Sha, PublicKeySize = (UInt32)(s_offsetToKeyData + pubKeyData.Length) }; using (var ms = new MemoryStream(160)) using (var binaryWriter = new BinaryWriter(ms)) { binaryWriter.Write(snPubKey.SigAlgId); binaryWriter.Write(snPubKey.HashAlgId); binaryWriter.Write(snPubKey.PublicKeySize); binaryWriter.Write(header.Type); binaryWriter.Write(header.Version); binaryWriter.Write(header.Reserved); binaryWriter.Write(header.AlgId); binaryWriter.Write(rsa.Magic); binaryWriter.Write(rsa.BitLen); binaryWriter.Write(rsa.PubExp); binaryWriter.Write(pubKeyData); return(ms.ToArray()); } }
public SolverParameters(RsaPubKey serverKey) : this() { if (serverKey == null) { throw new ArgumentNullException(nameof(serverKey)); } ServerKey = serverKey; }
public SolverClientSession(RsaPubKey serverKey) { if (serverKey == null) { throw new ArgumentNullException(nameof(serverKey)); } _Parameters = new SolverParameters(serverKey); InternalState = new State(); }
private unsafe static bool TryGetPublicKeyFromPublicKeyBlob(byte *blob, int blobLen, out ImmutableArray <byte> publicKey) { BlobHeader header = Marshal.PtrToStructure <BlobHeader>((IntPtr)blob); RsaPubKey rsaPubKey = Marshal.PtrToStructure <RsaPubKey>((IntPtr)(blob + sizeof(BlobHeader))); byte[] modulus = new byte[rsaPubKey.BitLen >> 3]; // The key blob data just contains the modulus if (blobLen - s_offsetToKeyData != modulus.Length) { publicKey = ImmutableArray <byte> .Empty; return(false); } Marshal.Copy((IntPtr)(blob + s_offsetToKeyData), modulus, 0, modulus.Length); publicKey = CreateSnPublicKeyBlob(header, rsaPubKey, modulus); return(true); }
internal unsafe static bool TryGetPublicKeyFromPrivateKeyBlob(byte[] blob, out byte[] publicKey) { fixed(byte *blobPtr = blob) { var header = (BlobHeader *)blobPtr; var rsa = (RsaPubKey *)(blobPtr + sizeof(BlobHeader)); var version = header->Version; var modulusBitLength = rsa->BitLen; var exponent = rsa->PubExp; var modulus = new byte[modulusBitLength >> 3]; if (blob.Length - s_offsetToKeyData < modulus.Length) { publicKey = null; return(false); } Marshal.Copy((IntPtr)(blobPtr + s_offsetToKeyData), modulus, 0, modulus.Length); var newHeader = new BlobHeader() { Type = PublicKeyBlobId, Version = version, Reserved = 0, AlgId = AlgorithmId.RsaSign }; var newRsaKey = new RsaPubKey() { Magic = RSA1, // Public key BitLen = modulusBitLength, PubExp = exponent }; publicKey = CreateSnPublicKeyBlob(newHeader, newRsaKey, modulus); return(true); } }
private unsafe static bool TryGetPublicKeyFromPrivateKeyBlob(byte *blob, int blobLen, out ImmutableArray <byte> publicKey) { BlobHeader *header = (BlobHeader *)blob; RsaPubKey * rsa = (RsaPubKey *)(blob + sizeof(BlobHeader)); byte version = header->Version; uint modulusBitLength = rsa->BitLen; uint exponent = rsa->PubExp; byte[] modulus = new byte[modulusBitLength >> 3]; if (blobLen - s_offsetToKeyData < modulus.Length) { publicKey = ImmutableArray <byte> .Empty; return(false); } Marshal.Copy((IntPtr)(blob + s_offsetToKeyData), modulus, 0, modulus.Length); BlobHeader newHeader = new BlobHeader() { Type = PublicKeyBlobId, Version = version, Reserved = 0, AlgId = AlgorithmId.RsaSign }; RsaPubKey newRsaKey = new RsaPubKey() { Magic = RSA1, // Public key BitLen = modulusBitLength, PubExp = exponent }; publicKey = CreateSnPublicKeyBlob(newHeader, newRsaKey, modulus); return(true); }
private unsafe static bool TryGetPublicKeyFromPrivateKeyBlob(byte* blob, int blobLen, out ImmutableArray<byte> publicKey) { var header = (BlobHeader*)blob; var rsa = (RsaPubKey*)(blob + sizeof(BlobHeader)); var version = header->Version; var modulusBitLength = rsa->BitLen; var exponent = rsa->PubExp; var modulus = new byte[modulusBitLength >> 3]; if (blobLen - s_offsetToKeyData < modulus.Length) { publicKey = ImmutableArray<byte>.Empty; return false; } Marshal.Copy((IntPtr)(blob + s_offsetToKeyData), modulus, 0, modulus.Length); var newHeader = new BlobHeader() { Type = PublicKeyBlobId, Version = version, Reserved = 0, AlgId = AlgorithmId.RsaSign }; var newRsaKey = new RsaPubKey() { Magic = RSA1, // Public key BitLen = modulusBitLength, PubExp = exponent }; publicKey = CreateSnPublicKeyBlob(newHeader, newRsaKey, modulus); return true; }
private static ImmutableArray<byte> CreateSnPublicKeyBlob(BlobHeader header, RsaPubKey rsa, byte[] pubKeyData) { var snPubKey = new SnPublicKeyBlob() { SigAlgId = AlgorithmId.RsaSign, HashAlgId = AlgorithmId.Sha, PublicKeySize = (UInt32)(s_offsetToKeyData + pubKeyData.Length) }; using (var ms = new MemoryStream(160)) using (var binaryWriter = new BinaryWriter(ms)) { binaryWriter.Write(snPubKey.SigAlgId); binaryWriter.Write(snPubKey.HashAlgId); binaryWriter.Write(snPubKey.PublicKeySize); binaryWriter.Write(header.Type); binaryWriter.Write(header.Version); binaryWriter.Write(header.Reserved); binaryWriter.Write(header.AlgId); binaryWriter.Write(rsa.Magic); binaryWriter.Write(rsa.BitLen); binaryWriter.Write(rsa.PubExp); binaryWriter.Write(pubKeyData); return ms.ToImmutable(); } }
public PromiseParameters(RsaPubKey serverKey) : this() { ServerKey = serverKey ?? throw new ArgumentNullException(nameof(serverKey)); }
public XORKey(RsaPubKey pubKey) : this(Utils.GenerateEncryptableInteger(pubKey._Key)) { }