System.Security.Cryptography.DSACryptoServiceProvider.IsPublic C# (CSharp) Method

IsPublic() private static method

Find whether a DSS key blob is public.
private static IsPublic ( byte keyBlob ) : bool
keyBlob byte
return bool
        private static bool IsPublic(byte[] keyBlob)
        {
            if (keyBlob == null)
            {
                throw new ArgumentNullException(nameof(keyBlob));
            }

            // The CAPI DSS public key representation consists of the following sequence:
            //  - BLOBHEADER (the first byte is bType)
            //  - DSSPUBKEY or DSSPUBKEY_VER3 (the first field is the magic field)

            // The first byte should be PUBLICKEYBLOB
            if (keyBlob[0] != CapiHelper.PUBLICKEYBLOB)
            {
                return false;
            }

            // Magic should be DSS_MAGIC or DSS_PUB_MAGIC_VER3
            if ((keyBlob[11] != 0x31 && keyBlob[11] != 0x33) || keyBlob[10] != 0x53 || keyBlob[9] != 0x53 || keyBlob[8] != 0x44)
            {
                return false;
            }

            return true;
        }

Usage Example

Beispiel #1
0
        public override void ImportParameters(DSAParameters parameters)
        {
            DSACspObject @object = DSACryptoServiceProvider.DSAStructToObject(parameters);

            if (this._safeKeyHandle != null && !this._safeKeyHandle.IsClosed)
            {
                this._safeKeyHandle.Dispose();
            }
            this._safeKeyHandle = SafeKeyHandle.InvalidHandle;
            if (DSACryptoServiceProvider.IsPublic(parameters))
            {
                Utils._ImportKey(Utils.StaticDssProvHandle, 8704, CspProviderFlags.NoFlags, (object)@object, ref this._safeKeyHandle);
            }
            else
            {
                KeyContainerPermission            containerPermission = new KeyContainerPermission(KeyContainerPermissionFlags.NoFlags);
                KeyContainerPermissionAccessEntry accessEntry         = new KeyContainerPermissionAccessEntry(this._parameters, KeyContainerPermissionFlags.Import);
                containerPermission.AccessEntries.Add(accessEntry);
                containerPermission.Demand();
                if (this._safeProvHandle == null)
                {
                    this._safeProvHandle = Utils.CreateProvHandle(this._parameters, this._randomKeyContainer);
                }
                Utils._ImportKey(this._safeProvHandle, 8704, this._parameters.Flags, (object)@object, ref this._safeKeyHandle);
            }
        }
All Usage Examples Of System.Security.Cryptography.DSACryptoServiceProvider::IsPublic