GCM 介绍

GCM有以下特点:

可以使用第三方应用服务器向Android应用推送消息
GCM不保证发送的消息的顺序,也不保证消息一定能够推送到手机(恩,谁也不能保证100%)
Android应用不需要运行就可以接收消息(是的,你没有看错,因为gcm被集成到系统中了,目前一些第三方的推送是在后台运行一个service维持长连接,与这些第三方推送相比,GCM不额外的耗电)
GCM只传递的数据(可以传递小于4kb的数据),对这些数据的处理可以全部由开发者控制(Google不对数据进行任何处理,仅仅转发一下而已)
对于Android4.04以上的系统使用GCM没有任何限制(国行手机也可以使用,截止2013年02月04日,android4.0+的份额为42.6%,随着4.0+版本的提升,Android的推送不再成为一个问题 Android版本分布),Android2.2以上的系统需要安装Google Play Store,Android2.2以下的系统不能够使用GCM
对于Android3.0以前的系统,需要在设备上设置google账号
gcm一次最多只能向1000部设备发送消息,没有提供向所有用户发送的接口(可能google认为向应用程序推送的消息都是与该用户相关的,如果你非要实现群发,一次发送1000个用户,多发送几次就行了)

App是运行在Android手机上的应用程序,GCM Server是Google的GCM服务器,Our Server是第三方应用服务器。具体流程如下:

App发送 SenderID到GCM Server注册接收推送信息(SendID是开发者在Google的网站开通GCM服务时,创建项目的项目号)。
GCM Server 向App返回RegId(RegId是GCM服务器通过一定算法生产的,可以唯一确定某一部手机上的某一个应用,这个RegId很重要)。
App向Our Server发送RegId(推送消息的时候要使用RegId,GCM服务器是使用RegId来确定某一部手机上的某一个应用接收消息的,所以第三方服务器需要保存它,需要注意的是RegId很长,比如可能有183位,存数据库时需要注意字段长度)
Our Server向GCM Server发送消息,传递appkey和RegId(appkey分为Oauth api key和simple api key)
GCM Server把消息推送给App

SIMPLE API KEY和OAUTH API KEY只能使用其中一个。不能同时使用。

消息在google server最长保留4个星期。这个时间可发送时自定义。

GCM经常收不到消息,让人抓狂。

msgcnt:消息的条数提示。在消息栏右下脚显示
message:消息内容
title:消息标题
如果不设置message参数,则不会弹出推送消息。(有title和msgcnt也没用)

開機後,GCM SERVICE默認自動開啟。如果禁止了就無法收到消息了。
國內有些設備沒有安裝GCM SERVICE和GOOGLE PLAY STORE,即使手動安裝了,也可能不能用的。因此無法使用GCM。
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
OpenSSL is a widely-used open-source cryptographic library that provides support for various cryptographic algorithms, including the GCM (Galois/Counter Mode) encryption mode. GCM is an authenticated encryption mode that provides both confidentiality and integrity. It combines the Counter (CTR) mode of encryption with a universal hash function called Galois Message Authentication Code (GMAC). GCM is commonly used for secure communication protocols like TLS. To use GCM with OpenSSL, you can utilize the EVP (Envelope) API provided by OpenSSL. Here's an example of how you can use OpenSSL to perform GCM encryption and decryption: ```c #include <openssl/evp.h> void encrypt_decrypt_gcm(const unsigned char* key, const unsigned char* iv, const unsigned char* aad, const unsigned char* ciphertext, int ciphertext_len, unsigned char* tag, unsigned char* plaintext) { EVP_CIPHER_CTX* ctx; int len; int plaintext_len; // Create and initialize the context ctx = EVP_CIPHER_CTX_new(); EVP_EncryptInit_ex(ctx, EVP_aes_256_gcm(), NULL, NULL, NULL); // Set the key and IV EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_KEY_LEN, 256, NULL); EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv); // Set the AAD (Additional Authenticated Data) EVP_EncryptUpdate(ctx, NULL, &len, aad, sizeof(aad)); // Perform the encryption EVP_EncryptUpdate(ctx, ciphertext, &len, plaintext, plaintext_len); // Finalize the encryption (generates the authentication tag) EVP_EncryptFinal_ex(ctx, ciphertext + len, &len); EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, 16, tag); // Cleanup EVP_CIPHER_CTX_free(ctx); } int main() { unsigned char key[32]; // 256-bit key unsigned char iv[12]; // 96-bit IV unsigned char aad[16]; // Additional Authenticated Data unsigned char ciphertext[128]; unsigned char tag[16]; unsigned char plaintext[128]; // Initialize the key, IV, AAD, and plaintext encrypt_decrypt_gcm(key, iv, aad, ciphertext, sizeof(ciphertext), tag, plaintext); return 0; } ``` In this example, you would need to replace the placeholders for the key, IV, AAD, ciphertext, and plaintext with the actual data you want to use. Additionally, make sure to include the necessary OpenSSL headers and link against the OpenSSL library when compiling. This is just a basic example and it's important to use proper cryptographic practices and ensure the security of your implementation. It's recommended to refer to the OpenSSL documentation and consult cryptographic experts for more guidance on using GCM with OpenSSL.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值