private static Certificate ExtractCertificate(byte[] data, byte[] providerKey) { var certificate = new Certificate(); if (data.Length != 116) { return(null); } certificate.MagicQuery = ArrayHelper.SubArray(data, 96, 8); var serial = ArrayHelper.SubArray(data, 104, 4); var tsBegin = ArrayHelper.SubArray(data, 108, 4); var tsEnd = ArrayHelper.SubArray(data, 112, 4); if (BitConverter.IsLittleEndian) { Array.Reverse(serial); Array.Reverse(tsBegin); Array.Reverse(tsEnd); } certificate.Serial = BitConverter.ToInt32(serial, 0); certificate.TsBegin = UnixTimeStampToDateTime(BitConverter.ToInt32(tsBegin, 0)); certificate.TsEnd = UnixTimeStampToDateTime(BitConverter.ToInt32(tsEnd, 0)); try { var m = PublicKeyAuth.Verify(data, providerKey); certificate.Valid = true; return(certificate); } catch (Exception) { } return(null); }
public void SimpleVerifyTest() { var expected = Encoding.UTF8.GetBytes("Adam Caudill"); var actual = PublicKeyAuth.Verify(Utilities.HexToBinary("8d5436accbe258a6b252c1140f38d7b8dc6196619945818b72512b6a8019d86dfeeb56f40c4d4b983d97dfeed37948527256c3567d6b253757fcfb32bef56f0b4164616d2043617564696c6c"), Utilities.HexToBinary("4ffda13c11d61d2b9568e54bec06ea59368e84874883087645e64e5e9653422e")); CollectionAssert.AreEqual(expected, actual); }
public void VerifyTest() { var kp = PublicKeyAuth.GenerateKeyPair(); byte[] message = System.Text.Encoding.UTF8.GetBytes("Hello, World!"); var signature = PublicKeyAuth.Sign(message, kp.Secret); var verification = PublicKeyAuth.Verify(signature, kp.Public); Assert.AreEqual(message.ToString(), verification.ToString()); }
public void VerifyAuthBadKey() { //Don`t copy bobSk for other tests (bad key)! //30 byte var bobSk = new byte[] { 0x5d, 0xab, 0x08, 0x7e, 0x62, 0x4a, 0x8a, 0x4b, 0x79, 0xe1, 0x7f, 0x8b, 0x83, 0x80, 0x0e, 0xe6, 0x6f, 0x3b, 0xb1, 0x29, 0x26, 0x18, 0xb6, 0xfd, 0x1c, 0x2f, 0x8b, 0x27, 0xff, 0x88 }; PublicKeyAuth.Verify(Encoding.UTF8.GetBytes("Adam Caudill"), bobSk); }
public void VerifyAuthBadKey() { //Don`t copy bobSk for other tests (bad key)! //30 byte var bobSk = new byte[] { 0x5d, 0xab, 0x08, 0x7e, 0x62, 0x4a, 0x8a, 0x4b, 0x79, 0xe1, 0x7f, 0x8b, 0x83, 0x80, 0x0e, 0xe6, 0x6f, 0x3b, 0xb1, 0x29, 0x26, 0x18, 0xb6, 0xfd, 0x1c, 0x2f, 0x8b, 0x27, 0xff, 0x88 }; var message = Encoding.UTF8.GetBytes("Adam Caudill"); Assert.Throws <KeyOutOfRangeException>( () => PublicKeyAuth.Verify(message, bobSk)); }
public void VerifyAuthWrongKey() { //Don`t copy bobSk for other tests (bad key)! //30 byte var bobSk = new byte[] { 0x5d, 0xab, 0x08, 0x7e, 0x62, 0x4a, 0x8a, 0x4b, 0x79, 0xe1, 0x7f, 0x8b, 0x83, 0x80, 0x0e, 0xe6, 0x6f, 0x3b, 0xb1, 0x29, 0x26, 0x18, 0xb6, 0xfd, 0x1c, 0x2f, 0x8b, 0x27, 0xff, 0x88, 0x88, 0x88 }; var message = Encoding.UTF8.GetBytes("Adam Caudill"); //It`s not really signed ... Assert.Throws <CryptographicException>( () => PublicKeyAuth.Verify(message, bobSk)); }
/// <summary> /// Verifies the message was signed with the private key that matches this public key. /// </summary> /// <param name='publicKey'> /// Public key. /// </param> /// <param name='signedMessage'> /// Signed message. /// </param> /// <returns> /// The decrypted (verified) message. /// </returns> public byte[] Verify(byte[] publicKey, byte[] signedMessage) { return(PublicKeyAuth.Verify(signedMessage, publicKey)); }