小编nis*_*662的帖子

Java 和 Android 之间的 Base64 编码/解码错误

我在 Java 和 Android 之间编码/解码 Base64 时遇到问题。

这是我的情况:

我在 Java 上使用 ECC 编写代码来加密/解密,我的代码运行良好。

然后我尝试在 Java 上加密字符串并在 Android 上解密这个加密的字符串,它失败了。

我认为问题可能是编码/解码 Base64。

这是我的代码:

仅在 Java 上加密/解密:

  //ENCRYPT
try {
        Cipher c = Cipher.getInstance("ECIES",BouncyCastleProvider.PROVIDER_NAME);
        c.init(Cipher.ENCRYPT_MODE,publicKey);
        encodeBytes = c.doFinal(origin.getBytes());

        String encrypt = Base64.getEncoder().encodeToString(encodeBytes);

        System.out.println("Encrypt:"+ encrypt+"\n");


    } catch (Exception e) {
        e.printStackTrace();
    }

//////DECRYPT
    try
    {
        String abc = Base64.getDecoder().decode(encrypt);
        Cipher c = Cipher.getInstance("ECIES","BC");
        c.init(Cipher.DECRYPT_MODE,privateKey);
        //decodeBytes = c.doFinal(encodeBytes);
        decodeBytes = c.doFinal(abc);
        String deCrypt = new String(decodeBytes,"UTF-8");

        System.out.println("Decrypt:"+ deCrypt +"\n");
    }
    catch (Exception ex)
    {
        ex.printStackTrace(); …
Run Code Online (Sandbox Code Playgroud)

java encryption base64 android

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

发送SMTP电子邮件时发生AuthenticationFailedException错误

我尝试在java中发送SMTP电子邮件,但我有这样的错误,我没有收到邮件.我关闭所有防火墙和防病毒软件.

错误:

javax.mail.AuthenticationFailedException: 534-5.7.14<https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbuIW

534-5.7.14 tAxHxbq4WR-vUuV1uOFAvx8NhInfxYTyNHi_8sJ80lX5lBdBla2ROiSKoysMNcFoQ6sGe
534-5.7.14 DUh173tDMolJ64W-Rahx1fhVF_08AvWrphibgQXiyyz5U1FNMMb-eGGJlUIbjyvBgQuZY6

534-5.7.14 tnykIXdVn__mg87aOmtxoss-EiFYeKdvuiBbt5eb9t_NOc97h-PkXOco-9FcYW69Iz9CTu

534-5.7.14 rfyhlo24k9oqIiWtcJwv85oUCO2g> Please log in via your web browser and

534-5.7.14 then try again.

534-5.7.14 Learn more at

534 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 pd8sm1306363pdb.93 - gsmtp   
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

private void btn_mailActionPerformed(java.awt.event.ActionEvent evt) {                                         

    String to = "receive.address@gmail.com";

    String from = "send.address@gmail.com";
    final String username = "send.address";
    final String password = "sendpassword";
    String host = "smtp.gmail.com";
    Properties pro = new Properties();
    pro.put("mail.smtp.host",host);
    pro.put("mail.smtp.socketFactory.port","465");
     pro.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
    pro.put("mail.smtp.auth","true");
     pro.put("mail.smtp.port","465");
    Session session = Session.getInstance(pro,
            new javax.mail.Authenticator() {
                protected …
Run Code Online (Sandbox Code Playgroud)

java smtp jakarta-mail

4
推荐指数
1
解决办法
7338
查看次数

如何在python中检查连接是否有效?

我在树莓派上使用 python 并使用阅读器 RDM880 使项目读取 RFID 标签。

我的想法是抽时间进出和工作人员检查是否按时工作。

我尝试使用python将card_ID、time_in、time_out添加到本地mysql和远程mysql(IP:192.168.137.1)。

它在远程和本地 mysql 中具有相同的表。

如果 mysql 远程坏了,我只想添加到本地 mysql。

这是我的代码:

import serial
import time
import RPi.GPIO as GPIO
import MySQLdb
from datetime import datetime
from binascii import hexlify
serial=serial.Serial("/dev/ttyAMA0",                    
                  baudrate=9600,                     
                  parity=serial.PARITY_NONE,                    
                  stopbits=serial.STOPBITS_ONE,                    
                  bytesize=serial.EIGHTBITS,
                  timeout=0.1) 
db_local = MySQLdb.connect("localhost","root","root","luan_van") #connect local
db = MySQLdb.connect("192.168.137.1", "root_a","","luan_van") #connect remote
ID_rong = 128187 # reader respone if no card
chuoi= "\xAA\x00\x03\x25\x26\x00\x00\xBB"
def RFID(str): #function read RFID via uart 
      serial.write(chuoi)
      data = serial.readline()
      tach_5 = data[5]
      tach_6 = data[6] …
Run Code Online (Sandbox Code Playgroud)

python python-3.x

3
推荐指数
3
解决办法
1万
查看次数

标签 统计

java ×2

android ×1

base64 ×1

encryption ×1

jakarta-mail ×1

python ×1

python-3.x ×1

smtp ×1