@@ -64,7 +64,7 @@ protected virtual byte[] DeriveDeviceSecret(byte[] sharedSecret)
6464 X25519PrivateKeyParameters ? clientPrivateKey = null , bool shouldCompress = false )
6565 {
6666 if ( ServerPublicKey == null )
67- throw new InvalidDataException ( "No server public key provided" ) ;
67+ throw new InvalidDataException ( "No server public key provided. " ) ;
6868
6969 const int headerSize = 0x4 + 0x20 + 0x10 ;
7070
@@ -186,7 +186,7 @@ private byte[] EncryptMessageInternal(BinaryWriter encryptedWriter, byte[] messa
186186 using var inputReader = new BinaryReader ( inputStream ) ;
187187
188188 if ( inputReader . ReadUInt32 ( ) != HeaderMagic )
189- throw new InvalidDataException ( "Invalid message header." ) ;
189+ throw new IOException ( "Invalid message header." ) ;
190190
191191 var clientEncPubKey = inputReader . ReadBytes ( 0x20 ) ;
192192 var expectedChecksum = inputReader . ReadBytes ( 0x10 ) ;
@@ -215,7 +215,7 @@ public byte[] DecryptResponseMessage(byte[] encrypted, byte[] sharedSecret)
215215 using var inputReader = new BinaryReader ( inputStream ) ;
216216
217217 if ( inputReader . ReadUInt32 ( ) != HeaderMagic )
218- throw new InvalidDataException ( "Invalid message header." ) ;
218+ throw new IOException ( "Invalid message header." ) ;
219219
220220 var iv = inputReader . ReadBytes ( 16 ) ;
221221 var expectedChecksum = inputReader . ReadBytes ( 16 ) ;
@@ -244,7 +244,7 @@ private byte[] DecryptMessageInternal(byte[] encryptedBody, byte[] key, byte[] i
244244 var checksum = checksumHash . Hash ! ;
245245
246246 if ( ! checksum . SequenceEqual ( expectedChecksum ) )
247- throw new InvalidDataException ( "Body checksum mismatch." ) ;
247+ throw new CryptographicException ( "Body checksum mismatch." ) ;
248248
249249 var decompressedLength = body [ 0 ] | ( body [ 1 ] << 8 ) | ( body [ 2 ] << 16 ) | ( body [ 3 ] << 24 ) ;
250250 var bodyData = body . Skip ( 4 ) . ToArray ( ) ;
@@ -285,7 +285,7 @@ public virtual byte[] DecryptVfs(byte[] dbData, bool skipVerification = false)
285285 var inputReader = new BinaryReader ( inputStream ) ;
286286
287287 if ( inputReader . ReadUInt32 ( ) != VfsHeaderMagic )
288- throw new InvalidDataException ( "Invalid database header." ) ;
288+ throw new IOException ( "Invalid database header." ) ;
289289
290290 return DecryptVfsInternal ( dbData , inputReader , skipVerification , ! skipVerification ? DeriveVfsPublicKey ( VfsCertConstants ) : "" ) ;
291291 }
@@ -296,7 +296,7 @@ protected static byte[] DecryptVfsInternal(byte[] dbData, BinaryReader inputRead
296296 var headerSize = fullHeaderSize - headerOffset ;
297297
298298 if ( dbData . Length < headerSize )
299- throw new InvalidDataException ( "Encrypted database too short." ) ;
299+ throw new IOException ( "Encrypted database too short." ) ;
300300
301301 var gcmAdd1 = inputReader . ReadUInt32 ( ) ;
302302 var gcmKey = inputReader . ReadBytes ( 0x10 ) ;
@@ -310,7 +310,7 @@ protected static byte[] DecryptVfsInternal(byte[] dbData, BinaryReader inputRead
310310 var encryptedLength = dbData . Length - headerSize ;
311311 var encryptedData = new byte [ encryptedLength + gcmTag . Length ] ;
312312 if ( inputReader . Read ( encryptedData , 0 , encryptedLength ) != encryptedLength )
313- throw new InvalidDataException ( "Failed to read encrypted data from database." ) ;
313+ throw new IOException ( "Failed to read encrypted data from database." ) ;
314314
315315 Buffer . BlockCopy ( gcmTag , 0 , encryptedData , encryptedLength , gcmTag . Length ) ;
316316
@@ -324,7 +324,7 @@ protected static byte[] DecryptVfsInternal(byte[] dbData, BinaryReader inputRead
324324 rsa . ImportFromPem ( publicKey ) ;
325325 var sigResult = rsa . VerifyHash ( signedData , signature , HashAlgorithmName . SHA1 , RSASignaturePadding . Pkcs1 ) ;
326326 if ( ! sigResult )
327- throw new InvalidDataException ( "Failed to verify VFS signature." ) ;
327+ throw new CryptographicException ( "Failed to verify VFS signature." ) ;
328328 }
329329
330330 var gcm = new GcmBlockCipher ( new AesEngine ( ) ) ;
@@ -339,7 +339,7 @@ protected static byte[] DecryptVfsInternal(byte[] dbData, BinaryReader inputRead
339339 }
340340 catch ( Exception ex )
341341 {
342- throw new InvalidDataException ( $ "Failed to decrypt database: { ex . Message } ") ;
342+ throw new CryptographicException ( $ "Failed to decrypt database: { ex . Message } ") ;
343343 }
344344
345345 var decompressedLength = decryptedData [ 0 ] | ( decryptedData [ 1 ] << 8 ) | ( decryptedData [ 2 ] << 16 ) | ( decryptedData [ 3 ] << 24 ) ;
0 commit comments