ที่ใช้เล่นคลายเครียด พร้อมได้ความรู้ เกี่ยวคำขวัญจังหวัดเพิ่มขึ้นอีกด้วย เพื่อนคนใหนมี iPhone ก็ลองโหลดเล่นได้นะครับ
Programming,Performance,Scalability
@interface ThumbImageView : UIImageView{
- (void)embedYouTube:(NSString *)urlString frame:(CGRect)frame {
NSString *embedHTML = @"starthtml starthead\ \ endhead startbody style=\"margin:0\">\
\
endbody endhtml";
NSString *html = [NSString stringWithFormat:embedHTML, urlString,
frame.size.width, frame.size.height];
if (!webView) {
webView = [[UIWebView alloc] initWithFrame:frame];
[self.view addSubview:webView];
}
[webView loadHTMLString:html baseURL:nil];
}
[self embedYouTube:self.url frame:CGRectMake(20, 20, 280, 300)];
float newScale = [imageScrollView zoomScale] * maxZoomLevel;
CGRect zoomRect = [self zoomRectForScale:newScale withCenter:tapPoint];
[imageScrollView zoomToRect:zoomRect animated:YES];
CGFloat tempx = view.center.x-160;
CGFloat tempy = view.center.y-160;
myScrollViewOffset = CGPointMake(tempx,tempy);
transaction.error.code != SKErrorPaymentCancelled
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction *transaction in transactions)
{
switch (transaction.transactionState)
{
case SKPaymentTransactionStatePurchased:
[self completeTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
[self failedTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
[self restoreTransaction:transaction];
default:
break;
}
}
}
- (void) failedTransaction: (SKPaymentTransaction *)transaction
{
if (transaction.error.code != SKErrorPaymentCancelled)
{
// Optionally, display an error here.
if([self.delegate respondsToSelector:@selector(failedTransaction:)])
[self.delegate failedTransaction:transaction];
}else {
if([self.delegate respondsToSelector:@selector(canceledTransaction:)])
[self.delegate canceledTransaction:transaction];
}
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}
- (void) completeTransaction: (SKPaymentTransaction *)transaction
{
if([self.delegate respondsToSelector:@selector(completeTransaction:)])
[self.delegate completeTransaction:transaction];
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}
- (void) restoreTransaction: (SKPaymentTransaction *)transaction
{
if([self.delegate respondsToSelector:@selector(restoreTransaction:)])
[self.delegate restoreTransaction:transaction];
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}
byte[] images = File.ReadAllBytes(@"C:\Wallpaper\encrypt.jpg");
string x = Convert.ToBase64String(images);
string result = DecryptString(x, "digix");
byte[] data = Convert.FromBase64String(result);
FileStream fsout = new FileStream(@"C:\Wallpaper\decrypt.jpg", FileMode.CreateNew);
fsout.Write(data, 0, data.Length);
fsout.Flush();
fsout.Close();
///
/// Encrpyts the sourceString, returns this result as an Aes encrpyted, BASE64 encoded string
///
/// a plain, Framework string (ASCII, null terminated)
/// The pass phrase.
///
/// returns an Aes encrypted, BASE64 encoded string
///
public static string EncryptString(string plainSourceStringToEncrypt, string passPhrase)
{
//Set up the encryption objects
using (AesCryptoServiceProvider acsp = GetProvider(Encoding.Default.GetBytes(passPhrase)))
{
byte[] sourceBytes = Encoding.ASCII.GetBytes(plainSourceStringToEncrypt);
ICryptoTransform ictE = acsp.CreateEncryptor();
//Set up stream to contain the encryption
MemoryStream msS = new MemoryStream();
//Perform the encrpytion, storing output into the stream
CryptoStream csS = new CryptoStream(msS, ictE, CryptoStreamMode.Write);
csS.Write(sourceBytes, 0, sourceBytes.Length);
csS.FlushFinalBlock();
//sourceBytes are now encrypted as an array of secure bytes
byte[] encryptedBytes = msS.ToArray(); //.ToArray() is important, don't mess with the buffer
//return the encrypted bytes as a BASE64 encoded string
return Convert.ToBase64String(encryptedBytes);
}
}
///
/// Decrypts a BASE64 encoded string of encrypted data, returns a plain string
///
/// an Aes encrypted AND base64 encoded string
/// The passphrase.
///returns a plain string
public static string DecryptString(string base64StringToDecrypt, string passphrase)
{
//Set up the encryption objects
using (AesCryptoServiceProvider acsp = GetProvider(Encoding.Default.GetBytes(passphrase)))
{
byte[] RawBytes = Convert.FromBase64String(base64StringToDecrypt);
ICryptoTransform ictD = acsp.CreateDecryptor();
//RawBytes now contains original byte array, still in Encrypted state
//Decrypt into stream
MemoryStream msD = new MemoryStream(RawBytes, 0, RawBytes.Length);
CryptoStream csD = new CryptoStream(msD, ictD, CryptoStreamMode.Read);
//csD now contains original byte array, fully decrypted
//return the content of msD as a regular string
return (new StreamReader(csD)).ReadToEnd();
}
}
private static AesCryptoServiceProvider GetProvider(byte[] key)
{
AesCryptoServiceProvider result = new AesCryptoServiceProvider();
result.BlockSize = 128;
result.KeySize = 128;
result.Mode = CipherMode.CBC;
result.Padding = PaddingMode.PKCS7;
result.GenerateIV();
result.IV = new byte[] {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
byte[] RealKey = GetKey(key, result);
result.Key = RealKey;
// result.IV = RealKey;
return result;
}
private static byte[] GetKey(byte[] suggestedKey, SymmetricAlgorithm p)
{
byte[] kRaw = suggestedKey;
ListkList = new List ();
for (int i = 0; i < p.LegalKeySizes[0].MinSize; i += 8)
{
kList.Add(kRaw[(i / 8) % kRaw.Length]);
}
byte[] k = kList.ToArray();
return k;
}