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

IsPublic() private static method

find whether an RSA 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 RSA public key representation consists of the following sequence:
            //  - BLOBHEADER
            //  - RSAPUBKEY

            // The first should be PUBLICKEYBLOB and magic should be RSA_PUB_MAGIC "RSA1"
            if (keyBlob[0] != CapiHelper.PUBLICKEYBLOB)
            {
                return false;
            }
            if (keyBlob[11] != 0x31 || keyBlob[10] != 0x41 || keyBlob[9] != 0x53 || keyBlob[8] != 0x52)
            {
                return false;
            }
            return true;
        }

Same methods

RSACryptoServiceProvider::IsPublic ( RSAParameters rsaParams ) : bool

Usage Example

        public override void ImportParameters(RSAParameters parameters)
        {
            if (this._safeKeyHandle != null && !this._safeKeyHandle.IsClosed)
            {
                this._safeKeyHandle.Dispose();
                this._safeKeyHandle = (SafeKeyHandle)null;
            }
            RSACspObject @object = RSACryptoServiceProvider.RSAStructToObject(parameters);

            this._safeKeyHandle = SafeKeyHandle.InvalidHandle;
            if (RSACryptoServiceProvider.IsPublic(parameters))
            {
                Utils._ImportKey(Utils.StaticProvHandle, 41984, CspProviderFlags.NoFlags, (object)@object, ref this._safeKeyHandle);
            }
            else
            {
                if (!CompatibilitySwitches.IsAppEarlierThanWindowsPhone8)
                {
                    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, 41984, this._parameters.Flags, (object)@object, ref this._safeKeyHandle);
            }
        }
All Usage Examples Of System.Security.Cryptography.RSACryptoServiceProvider::IsPublic