我从参考文章上看,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!
--
您收到此邮件是因为您订阅了 Google 网上论坛的“OpenSocial 中文讨论组”论坛。
要向此网上论坛发帖,请发送电子邮件至 opensoci...@googlegroups.com。
要取消订阅此网上论坛,请发送电子邮件至 opensocial-chi...@googlegroups.com。
若有更多问题,请通过 http://groups.google.com/group/opensocial-china?hl=zh-CN 访问此网上论坛。