小编X F*_* Fa的帖子

如何在php和android之间加密和解密数据

这些是我用来加密和解密基于 php 的服务器和 Android 应用程序之间的数据的类。

有时 php 解密类不起作用:

例如,当我在android中加密“abc”或“zdf”或“091360532561524369510”时,php类无法从android客户端解密加密数据。

你能检查一下这些课程吗? java类:

import java.security.NoSuchAlgorithmException;

import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

public class ApiCrypter
{
    private String iv= "0123456789012345";
    private String secretkey= "9876543210987654";
    private IvParameterSpec ivspec;
    private SecretKeySpec keyspec;
    private Cipher cipher;

    public ApiCrypter()
    {
        ivspec = new IvParameterSpec(iv.getBytes());
        keyspec = new SecretKeySpec(secretkey.getBytes(), "AES");

        try {
            cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (NoSuchPaddingException e) {
            e.printStackTrace();
        }
    }

    public byte[] encrypt(String text) throws Exception
    { …
Run Code Online (Sandbox Code Playgroud)

php java encryption

5
推荐指数
1
解决办法
4045
查看次数

当应用程序在后台运行时,如何显示自定义UI用于Firebase通知?

我使用此类显示从Firebase控制台收到的自己的UI(RemoteViews)的通知。当应用程序是前台应用程序时,这很好用,但是当应用程序在后台运行时,通知以默认的设备样式显示。即使应用程序是前台或后台,我应该怎么做才能在自己的UI中显示通知?

public class MyFirebaseMessagingService extends FirebaseMessagingService {

    private static final String TAG = "Mehdi";

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage)
    {
        super.onMessageReceived(remoteMessage);

        if (remoteMessage.getNotification() != null)
        {
            RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.payam_notification_layout);
            contentView.setTextViewText(R.id.payam,remoteMessage.getNotification().getBody());

            String channelId = "Default";
            NotificationCompat.Builder mBuilder =
                    new NotificationCompat.Builder(this,channelId)
                            .setSmallIcon(R.drawable.status_icon_delivered)
                            .setLargeIcon(BitmapFactory.decodeResource( getResources(), R.mipmap.icon))
                            .setSound(Uri.parse("android.resource://" + getApplicationContext().getPackageName() + "/" + R.raw.notification))
                            .setCustomBigContentView(contentView)
                            .setContentTitle(remoteMessage.getNotification().getTitle())
                            .setContentText(remoteMessage.getNotification().getBody())
                            .setAutoCancel(true);

            NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                NotificationChannel channel = new NotificationChannel(channelId, "Default channel", NotificationManager.IMPORTANCE_DEFAULT);
                manager.createNotificationChannel(channel);
            }
            manager.notify(0, mBuilder.build());
        } …
Run Code Online (Sandbox Code Playgroud)

notifications android remoteview firebase

2
推荐指数
1
解决办法
1046
查看次数

标签 统计

android ×1

encryption ×1

firebase ×1

java ×1

notifications ×1

php ×1

remoteview ×1