Esempio n. 1
0
        public static EncryptedProperties Create(Stream stream, LogOnIdentity identity)
        {
            if (identity == null)
            {
                throw new ArgumentNullException("identity");
            }
            if (identity == LogOnIdentity.Empty)
            {
                return(Invalid);
            }

            EncryptedProperties properties = new EncryptedProperties(null);

            using (IAxCryptDocument document = New <AxCryptFactory>().CreateDocument(identity.DecryptionParameters(), stream))
            {
                if (!document.PassphraseIsValid)
                {
                    return(Invalid);
                }

                properties = new EncryptedProperties(document.FileName);
                properties.SharedKeyHolders               = document.AsymmetricRecipients;
                properties.DecryptionParameter            = document.DecryptionParameter;
                properties.FileMetaData.CreationTimeUtc   = document.CreationTimeUtc;
                properties.FileMetaData.LastWriteTimeUtc  = document.LastWriteTimeUtc;
                properties.FileMetaData.LastAccessTimeUtc = document.LastAccessTimeUtc;
                properties.IsValid = true;
            }

            return(properties);
        }
        private static IAxCryptDocument Document(Stream source, LogOnIdentity identity, string displayContext, IProgressContext progress)
        {
            if (identity == null)
            {
                throw new ArgumentNullException(nameof(identity));
            }

            IAxCryptDocument document = New <AxCryptFactory>().CreateDocument(identity.DecryptionParameters(), new ProgressStream(source, progress));

            return(document);
        }
Esempio n. 3
0
        public static bool IsKeyShared(this IDataStore dataStore, LogOnIdentity decryptIdentity)
        {
            if (!dataStore.IsEncrypted())
            {
                return(false);
            }

            OpenFileProperties properties = OpenFileProperties.Create(dataStore);

            if (properties.IsLegacyV1 || properties.V2AsymetricKeyWrapCount <= 1)
            {
                return(false);
            }

            if (decryptIdentity == LogOnIdentity.Empty)
            {
                return(false);
            }

            using (Stream stream = dataStore.OpenRead())
            {
                using (IAxCryptDocument document = New <AxCryptFactory>().CreateDocument(decryptIdentity.DecryptionParameters(), stream))
                {
                    if (!document.PassphraseIsValid)
                    {
                        return(false);
                    }

                    return(document.AsymmetricRecipients.Select(ar => ar.Email).Distinct().Skip(1).Any());
                }
            }
        }