internal static byte[] DecryptSharingKey(R.Vault vaultResponse, byte[] key) { if (vaultResponse.PrivateKey.IsNullOrEmpty() || vaultResponse.SharingKey.IsNullOrEmpty()) { return(null); } var privateKeyComponents = Util.Decrypt(vaultResponse.PrivateKey.Decode64(), key).ToUtf8().Split(','); if (privateKeyComponents.Length != 8) { throw new InternalErrorException("Invalid RSA key format"); } var rsaKey = new RSAParameters() { Modulus = privateKeyComponents[0].DecodeHexLoose(), Exponent = privateKeyComponents[1].ToBigInt().ToByteArray(), D = privateKeyComponents[2].DecodeHexLoose(), P = privateKeyComponents[3].DecodeHexLoose(), Q = privateKeyComponents[4].DecodeHexLoose(), DP = privateKeyComponents[5].DecodeHexLoose(), DQ = privateKeyComponents[6].DecodeHexLoose(), InverseQ = privateKeyComponents[7].DecodeHexLoose(), }; return(Crypto.DecryptRsa(vaultResponse.SharingKey.DecodeHex(), rsaKey, RSAEncryptionPadding.Pkcs1)); }
internal static Account[] ParseAccounts(R.Vault vaultResponse, byte[] vaultKey, byte[] sharingKey) { // TODO: Test on non account type secrets! // TODO: Test on accounts with missing fields! return(vaultResponse.Secrets .Select(x => ParseAccount(x, x.IsShared == "YES" ? sharingKey : vaultKey)) .Where(x => x != null) .ToArray()); }