[搭建opensocial平台] 用ruby计算token传递给php shindig中遇到的问题。

14 views
Skip to first unread message

Alex

unread,
Jan 21, 2010, 4:51:26 AM1/21/10
to OpenSocial 中文讨论组
参考文章:
http://www.chabotc.com/generic/using-shindig-in-a-non-php-or-java-envirionment/

我从参考文章上看,ruby搭建opensocial平台需要做到2点(以php shindig为基础):
1. 计算security token传递给shindig(a. 用ruby算法计算token,b.建立自己的crypto并扩展class;
作者认为a简单些)
2. 从sns获取social data并处理
======================================
我选择了用ruby计算token。大部分的php计算token的算法可以用ruby翻译,
so,我遇到了一点小问题:

- php 方法:
----------------------------------------------
public static function aes128cbcEncrypt($key, $text) {
/* Open the cipher */
$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC,
'');
if (! $td) {
throw new GeneralSecurityException('Invalid mcrypt cipher, check
your libmcrypt library and php-mcrypt extention');
}
// replaced MCRYPT_DEV_RANDOM with MCRYPT_RAND since windows
doesn't have /dev/rand :)
srand((double)microtime() * 1000000);
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
/* Intialize encryption */
mcrypt_generic_init($td, $key, $iv);
/* Encrypt data */
$encrypted = mcrypt_generic($td, $text);
/* Terminate encryption handler */
mcrypt_generic_deinit($td);
/*
* AES-128-CBC encryption. The IV is returned as the first 16
bytes
* of the cipher text.
*/
return $iv . $encrypted;
}

- 我用ruby翻译的方法:
----------------------------------------------
def aes128cbcEncrypt(key,text)
c = OpenSSL::Cipher::Cipher.new("aes-128-cbc")
c.encrypt
# your pass is what is used to encrypt/decrypt
c.key = key = Digest::SHA1.hexdigest(key)
c.iv = iv = c.random_iv
e = c.update(text)
e << c.final
# AES-128-CBC encryption. The IV is returned as the first 16 bytes
# of the cipher text.
return iv + e
end
----------------------------------------------
这个方法产生的加密结果与相应的php方法(上面的那个php方法)产生的结果不同。
希望有配置过ruby on rails环境下的成功者,以及有经验的朋友给予一些帮助。
谢谢 thank you!

Alex

unread,
Jan 21, 2010, 4:50:11 AM1/21/10
to OpenSocial 中文讨论组

p l

unread,
Jan 25, 2010, 2:30:35 AM1/25/10
to opensoci...@googlegroups.com
您可以采用如下方法进行,
 
1,建设好php shindig
2,将php中做st的方式提取,做成一个私密的接口
3,在访问ruby的应用页面时,去读取php的st秘密接口,获得st的字符串
4,生成应用的iframe url,这时的ruby应用页面就做好了。
2010/1/21 Alex <dequa...@gmail.com>
--
您收到此邮件是因为您订阅了 Google 网上论坛的“OpenSocial 中文讨论组”论坛。
要向此网上论坛发帖,请发送电子邮件至 opensoci...@googlegroups.com
要取消订阅此网上论坛,请发送电子邮件至 opensocial-chi...@googlegroups.com
若有更多问题,请通过 http://groups.google.com/group/opensocial-china?hl=zh-CN 访问此网上论坛。




Reply all
Reply to author
Forward
0 new messages