"On iOS this could default to the native implementation" - I really would like to know if it WILL. Are they compatible? Meaning: If I used SHA256Managed so far and now switch, can data still be decrypted?
René 2012/7/10 Alan <[email protected]> > Hey, > > Don't use 'new SHA256Managed', use 'SHA256.Create ()'. This way the > mono runtime will be able to select the 'best' SHA256 implementation > to use. On iOS this could default to the native implementation, on > desktop this will default to SHA256Managed. > > Alan > > On 10 July 2012 12:28, René Ruppert <[email protected]> wrote: > > Hi, > > > > from the docs of 5.3: > > > > Common Crypto > > > > MonoTouch will now use the iOS CommonCrypto libraries to provide some of > the > > functionality exposed by its APIs. This replaces our managed > implementations > > with the native versions. It is now used for for digest (hash) and > symmetric > > ciphers, leveraging the hardware acceleration for SHA-1 and AES under the > > right circumstances. > > > > > > I'm using code like the one below for hashing and encryption. How can I > take > > advantage of HW crypto? Or will it automatically become faster? > > > > /// <summary> > > > > /// Calculates the SHA256 hash value of the data <c>b</c>. > > > > /// </summary> > > > > /// <detail declaration="public static"/> > > > > /// <param name="b" type="byte[]">The data of which the hash value is > > calculated.</param> > > > > /// <returns type="byte[]">The SHA256 hash value of <c>b</c>.</returns> > > > > public static byte[] CalculateHash ( byte[] b ) > > > > { > > > > SHA256Managed oSha = new SHA256Managed (); > > > > byte[] aHash = oSha.ComputeHash ( b ); > > > > return aHash; > > > > } > > > > /// <summary> > > > > /// Computes SHA256 hash from a string > > > > /// </summary> > > > > /// <param name="sData"></param> > > > > /// <returns></returns> > > > > public static string ComputeSHA256HashUnicode ( string sData ) > > > > { > > > > byte[] aData, aHash; > > > > > > UnicodeEncoding oEncoding = new UnicodeEncoding (); > > > > aData = oEncoding.GetBytes ( sData ); > > > > aHash = CalculateHash(aData); > > > > string sResult = oEncoding.GetString ( aHash ); > > > > return sResult; > > > > } > > > > > > > > public static void Crypt ( Stream oFileIn, Stream oFileOut, > ICryptoTransform > > oTrans ) > > > > { > > > > // Declare local variables > > > > byte[] buf = new byte[ 4096]; // Read buffer > > > > int iLen; // Current buffer length > > > > long lReadLen = 0; // Total number of bytes written. > > > > long lTotLen = oFileIn.Length; // Total length of the input file. > > > > > > // Move to the beginning of the file > > > > if ( oFileIn.Position > 0 && oFileIn.CanSeek ) > > > > oFileIn.Seek ( 0, SeekOrigin.Begin ); > > > > > > // Create the cryptographic stream > > > > CryptoStream encStream = new CryptoStream (oFileOut, oTrans, > > CryptoStreamMode.Write); > > > > > > // Read from the input file, then encrypt/decrypt and write to the output > > file. > > > > while ( lReadLen < lTotLen ) > > > > { > > > > iLen = oFileIn.Read ( buf, 0, buf.Length ); > > > > encStream.Write ( buf, 0, iLen ); > > > > lReadLen += iLen; > > > > } > > > > // Clean up > > > > encStream.Close (); > > > > } > > > > > > > > René > > > > > > _______________________________________________ > > MonoTouch mailing list > > [email protected] > > http://lists.ximian.com/mailman/listinfo/monotouch > > >
_______________________________________________ MonoTouch mailing list [email protected] http://lists.ximian.com/mailman/listinfo/monotouch
