コード例 #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
        }
コード例 #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));
                }
            }
        }
コード例 #3
0
        // TODO: pull all the TypeRefs needed for the NSDictionary

        public static SecStatusCode GenerateKeyPair(NSDictionary parameters, out SecKey publicKey, out SecKey privateKey)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            IntPtr pub, priv;

            var res = SecKeyGeneratePair(parameters.Handle, out pub, out priv);

            if (res == SecStatusCode.Success)
            {
                publicKey  = new SecKey(pub, true);
                privateKey = new SecKey(priv, true);
            }
            else
            {
                publicKey = privateKey = null;
            }
            return(res);
        }