Superyeti420's Blog


I’ve Moved!
February 25, 2011, 9:43 am
Filed under: Uncategorized | Tags:

Hi everyone. Well i decided to finally host my own blog on my own domain using Orchard CMS. It seems pretty cool so far, got all my posts from here moved over, and will now shorten them and link to the new ones, and everything new will be over there. Feel free to check it out. http://blog.it1services.ca



ABAddressBook Helper
November 20, 2010, 7:48 am
Filed under: MonoTouch

Hey everyone, while working on my latest project, i discovered the need to search the address book for a phone number. Through my travels, I DID discover that it seems this functionality isn’t exposed by default with the native iOS libraries, or if it is, its with NSArrays, and NSObjects which can be slower than native MT components. So with a bit of help from Clancy, i came up with this helper class for the MonoTouch ABAddressBook. Enjoy.


public class ContactHelper
{
public ContactHelper ()
{

}

public static ABPerson PickContact(UIViewController view){

ABPeoplePickerNavigationController picker = new ABPeoplePickerNavigationController();

ABPerson ret = null;

picker.SelectPerson += delegate(object sender, ABPeoplePickerSelectPersonEventArgs e) {
picker.DismissModalViewControllerAnimated(true);
ret = e.Person;
};

picker.Cancelled += delegate {
picker.DismissModalViewControllerAnimated(true);
};

view.PresentModalViewController(picker, true);

return ret;

}

public static ABPerson SearchByPhoneNumber(string phoneNumber)
{
List singlePeople = new List();
phoneNumber = Regex.Replace(phoneNumber,"[^0-9]", "");
ABAddressBook ab = new ABAddressBook();

var people = ab.Where(x=> x is ABPerson).Cast().Where(x=> x.GetPhones().Where(p=> Regex.Replace(p.Value,"[^0-9]", "").Contains(phoneNumber) || phoneNumber.Contains(Regex.Replace(p.Value,"[^0-9]", ""))).Count() > 0).ToArray();
foreach(var person in people)
{
if( singlePeople.Intersect(person.GetRelatedNames().Cast()).Count() <= 0)
singlePeople.Add(person);

}
return singlePeople.ToArray().First();
}

}



Updates to SuperYeti/MonoTouch.Dialog
August 25, 2010, 6:16 am
Filed under: MonoTouch, MonoTouch.Dialog

I fixed up the BooleanImageElement to draw the On/Off slider in the correct location on the view now, it detects what device it is, and based on that it changes the X value accordingly. http://github.com/SuperYeti/MonoTouch.Dialog



Im Back hehe new updates to MonoTouch.Dialog.Extensions

Well after a bit of a hiatus on iOS Dev, i’m back. I added a new “SpiffyDialogViewController” to the MT.D.Ext library today. Its based off of Miguel’s code sample in MT.d to do a backgroun image on a UITable, but wasn’t working correctly on the iPad aka not at all. So i did some research figured out where it was failing and fixed it. silly SDK version inconsistencies. Well its all good to go now, and uploaded to. http://github.com/SuperYeti/MonoTouch.Dialog.Extensions feel free to add to it or any comments or suggestions are always welcomed. Cheers.



MonoTouch.Dialog.Extensions Release
May 13, 2010, 1:18 am
Filed under: MonoTouch, MonoTouch.Dialog, MonoTouch.Dialog.Extensions

Hey everyone. I’ve released the 1st version of MonoTouch.Dialog.Extensions at http://github.com/SuperYeti/MonoTouch.Dialog.Extensions. The first addition is a UrlImageStringElement extension that will load an image and caption from a URL, save the image on the file system, and create a thumbnail for it. This also utilizes an LRU cache, and download throttling mechanism thanks to Miguel for that. Check it out, and let me know what other extensions you’d like to see on it in the future. Cheers.

UPDATE: I just added in a search bar, and image cache management for clearing the cache. I made the sample app a little google images search tool.

http://github.com/SuperYeti/MonoTouch.Dialog.Extensions.



MonoTouch.DirectoryRecurser
May 11, 2010, 3:46 am
Filed under: MonoTouch, MonoTouch.Dialog

Well today i built a quick little File system browser for the iPhone using MonoTouch.Dialog as a little POC. It goes and recurses your documents directory, and allows you to navigate through the folder structure, and click on files to see an alert with the name.



SuperYeti/MonoTouch.Dialog updates
May 10, 2010, 8:14 pm
Filed under: MonoTouch, MonoTouch.Dialog

Well Miguel went to merge some/all of my changes on my fork into trunk today, and there were a ton of whitespace and formatting changes. i went through and cleaned these up, and pulled from trunk to make it more consistent. While i was in there i included all of Miguel’s recent changes, and made his new changes, and my old ones play nice together. Essentially the merge is done, miguel just has to decide which of the changes he wants to keep. in any case, please find the url below, and check it out for yourself if wanted. Cheers.

http://github.com/SuperYeti/MonoTouch.Dialog/



caulker extensions
May 7, 2010, 6:23 am
Filed under: MonoTouch

hey guys, today FAK finally released his AWESOME 3d mapping library, and i began to cut my teeth on it. it annoyed me that double tap wasn’t there so i added it in, and removed the tilt during zoom functionality as well. I was thinking either 3 touch tilt (ahill’s idea) or maybe a touch and hold button and use the accelerometer to tilt your display of the map, that’d be kinda cool. Also i think the compass, and gps should be tied into the core library, for map orientation, and location capabilitites. I’ll be adding this release to FAK’s source if he wants when he gets back, but i wanted to start a good forum on ideas/suggestions for the library while it was fresh until FAK gets up a forum, or suggestion list. Cheers Warren. I’m lazy and didnt feel like posting the file elsewhere. Just right-click and save-as the link below and remove the .jpg extension from the file to reveal the tar.gz. l8rs

Download Source Here, rename to *.tar.gz



UPDATE: MonoTouch Compatible Encryption Functions
May 6, 2010, 6:27 pm
Filed under: MonoTouch

Hey guys, i was informed that i used a weak cipher combination on my last post and example. I’ve done some more reading, learned a ton more about encryption today :) , and have come up with this based on the MSDN examples, and some more reading. Cheers.


public static class PageSecurity
    {
        private const string bKey = "Fvjh834funw0uw34nf9we80yfw07FYB3Q4FNH74329";

        private static byte[] bSalt {
            get { return new byte[] { 0x23, 0x5e, 0x2d, 0x65, 0x94, 0x7a, 0x62, 0x64, 0x5d, 0x3c,0xe3, 0xee, 0xfa }; }
        }

        public static string EncryptString (string plainText)
        {
            Rfc2898DeriveBytes rdb = new Rfc2898DeriveBytes (bKey + UIDevice.CurrentDevice.UniqueIdentifier, bSalt);

            byte[] Key = rdb.GetBytes (32);

            byte[] IV = rdb.GetBytes (16);

            // Check arguments.
            if (plainText == null || plainText.Length <= 0)
                throw new ArgumentNullException ("plainText");
            if (Key == null || Key.Length <= 0)
                throw new ArgumentNullException ("Key");
            if (IV == null || IV.Length <= 0)
                throw new ArgumentNullException ("IV");

            // Declare the stream used to encrypt to an in memory
            // array of bytes.
            MemoryStream msEncrypt = null;

            // Declare the RijndaelManaged object
            // used to encrypt the data.
            RijndaelManaged aesAlg = null;

            try {
                // Create a RijndaelManaged object
                // with the specified key and IV.
                aesAlg = new RijndaelManaged ();
                aesAlg.Key = Key;
                aesAlg.IV = IV;

                // Create a decrytor to perform the stream transform.
                ICryptoTransform encryptor = aesAlg.CreateEncryptor (aesAlg.Key, aesAlg.IV);

                // Create the streams used for encryption.
                msEncrypt = new MemoryStream ();
                using (CryptoStream csEncrypt = new CryptoStream (msEncrypt, encryptor, CryptoStreamMode.Write)) {
                    using (StreamWriter swEncrypt = new StreamWriter (csEncrypt)) {

                        //Write all data to the stream.
                        swEncrypt.Write (plainText);
                    }
                }
            } finally {
                // Clear the RijndaelManaged object.
                if (aesAlg != null)
                    aesAlg.Clear ();
            }

            // Return the encrypted bytes from the memory stream.
            byte[] retArray = msEncrypt.ToArray ();

            return Convert.ToBase64String (retArray, 0, retArray.Length);

        }

        public static string DecryptString (string cipher)
        {
            Rfc2898DeriveBytes rdb = new Rfc2898DeriveBytes (bKey + UIDevice.CurrentDevice.UniqueIdentifier, bSalt);

            byte[] Key = rdb.GetBytes (32);

            byte[] IV = rdb.GetBytes (16);

            byte[] cipherText = Convert.FromBase64String (cipher);

            // Check arguments.
            if (cipherText == null || cipherText.Length <= 0)
                throw new ArgumentNullException ("cipherText");
            if (Key == null || Key.Length <= 0)
                throw new ArgumentNullException ("Key");
            if (IV == null || IV.Length <= 0)
                throw new ArgumentNullException ("IV");

            // Declare the RijndaelManaged object
            // used to decrypt the data.
            RijndaelManaged aesAlg = null;

            // Declare the string used to hold
            // the decrypted text.
            string plaintext = null;

            try {
                // Create a RijndaelManaged object
                // with the specified key and IV.
                aesAlg = new RijndaelManaged ();
                aesAlg.Key = Key;
                aesAlg.IV = IV;

                // Create a decrytor to perform the stream transform.
                ICryptoTransform decryptor = aesAlg.CreateDecryptor (aesAlg.Key, aesAlg.IV);
                // Create the streams used for decryption.
                using (MemoryStream msDecrypt = new MemoryStream (cipherText)) {
                    using (CryptoStream csDecrypt = new CryptoStream (msDecrypt, decryptor, CryptoStreamMode.Read)) {
                        using (StreamReader srDecrypt = new StreamReader (csDecrypt))

                            // Read the decrypted bytes from the decrypting stream
                            // and place them in a string.
                            plaintext = srDecrypt.ReadToEnd ();
                    }
                }
            } finally {
                // Clear the RijndaelManaged object.
                if (aesAlg != null)
                    aesAlg.Clear ();
            }

            return plaintext;
        }

        public static string EncryptString (int value)
        {
            return EncryptString (value.ToString ());

        }
    }



MonoTouch compatible Encryption Functions
May 6, 2010, 6:01 am
Filed under: MonoTouch

Hey everyone. I threw this together a week ago to facilitate xml serialization of .net objects and storing them encrypted in StandardUserDefaults, or for transmitting encrypted data or whatever. Here’s the class enjoy.


public static class PageSecurity
{
private const string bkey = "AnyAlphaNumbericStr1ng";

public static string EncryptString(string toEncrypt)
{
byte[] keyArray;
byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(toEncrypt);

MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(bkey));

TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
tdes.Key = keyArray;
tdes.Mode = CipherMode.ECB;
tdes.Padding = PaddingMode.PKCS7;

ICryptoTransform cTransform = tdes.CreateEncryptor();
byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);

return Convert.ToBase64String(resultArray, 0, resultArray.Length);

}

public static string EncryptString(int value)
{
return EncryptString(value.ToString());

}

public static string DecryptString(string toDecrypt)
{
byte[] keyArray;
byte[] toEncryptArray = Convert.FromBase64String(toDecrypt);

MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(bkey));

TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
tdes.Key = keyArray;
tdes.Mode = CipherMode.ECB;
tdes.Padding = PaddingMode.PKCS7;

ICryptoTransform cTransform = tdes.CreateDecryptor();
byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);

return UTF8Encoding.UTF8.GetString(resultArray);
}
}




Follow

Get every new post delivered to your Inbox.