Esempio n. 1
0
        public static SecStatusCode GenerateKeyPair(SecKeyType type, int keySizeInBits, SecPublicPrivateKeyAttrs publicAndPrivateKeyAttrs, out SecKey publicKey, out SecKey privateKey)
        {
#if !MONOMAC
            // iOS (+friends) need to pass the strong dictionary for public and private key attributes to specific keys
            // instead of merging them with other attributes.
            return(GenerateKeyPair(type, keySizeInBits, publicAndPrivateKeyAttrs, publicAndPrivateKeyAttrs, out publicKey, out privateKey));
#else
            if (type == SecKeyType.Invalid)
            {
                throw new ArgumentException("invalid 'SecKeyType'", nameof(type));
            }

            NSMutableDictionary dic;
            if (publicAndPrivateKeyAttrs != null)
            {
                dic = new NSMutableDictionary(publicAndPrivateKeyAttrs.GetDictionary());
            }
            else
            {
                dic = new NSMutableDictionary();
            }
            dic.LowlevelSetObject(type.GetConstant(), SecAttributeKey.Type);
            dic.LowlevelSetObject(new NSNumber(keySizeInBits), SecKeyGenerationAttributeKeys.KeySizeInBitsKey.Handle);
            return(GenerateKeyPair(dic, out publicKey, out privateKey));
#endif
        }
Esempio n. 2
0
        public static SecStatusCode GenerateKeyPair(SecKeyType type, int keySizeInBits, SecPublicPrivateKeyAttrs publicKeyAttrs, SecPublicPrivateKeyAttrs privateKeyAttrs, out SecKey publicKey, out SecKey privateKey)
        {
            if (type == SecKeyType.Invalid)
            {
                throw new ArgumentException("invalid 'SecKeyType'", nameof(type));
            }

            using (var dic = new NSMutableDictionary()) {
                dic.LowlevelSetObject(type.GetConstant(), SecAttributeKey.Type);
                using (var ksib = new NSNumber(keySizeInBits)) {
                    dic.LowlevelSetObject(ksib, SecKeyGenerationAttributeKeys.KeySizeInBitsKey.Handle);
                    if (publicKeyAttrs != null)
                    {
                        dic.LowlevelSetObject(publicKeyAttrs.GetDictionary(), SecKeyGenerationAttributeKeys.PublicKeyAttrsKey.Handle);
                    }
                    if (privateKeyAttrs != null)
                    {
                        dic.LowlevelSetObject(privateKeyAttrs.GetDictionary(), SecKeyGenerationAttributeKeys.PrivateKeyAttrsKey.Handle);
                    }
                    return(GenerateKeyPair(dic, out publicKey, out privateKey));
                }
            }
        }