我在php中有一个web服务,它生成一个用于加密消息的密钥对,以及一个用于检索私钥并解密消息的java应用程序.
对于php我正在使用http://phpseclib.sourceforge.net/并拥有这两个文件:
keypair.php
<?php
set_time_limit(0);
if( file_exists('private.key') )
{
echo file_get_contents('private.key');
}
else
{
include('Crypt/RSA.php');
$rsa = new Crypt_RSA();
$rsa->createKey();
$res = $rsa->createKey();
$privateKey = $res['privatekey'];
$publicKey = $res['publickey'];
file_put_contents('public.key', $publicKey);
file_put_contents('private.key', $privateKey);
}
?>
Run Code Online (Sandbox Code Playgroud)
encrypt.php
<?php
include('Crypt/RSA.php');
//header("Content-type: text/plain");
set_time_limit(0);
$rsa = new Crypt_RSA();
$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_OAEP);
$rsa->loadKey(file_get_contents('public.key')); // public key
$plaintext = 'Hello World!';
$ciphertext = $rsa->encrypt($plaintext);
echo base64_encode($ciphertext);
?>
Run Code Online (Sandbox Code Playgroud)
在java中我有这个代码:
package com.example.app;
import java.io.DataInputStream;
import java.net.URL;
import java.security.Security;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import sun.misc.BASE64Decoder;
public class MainClass …Run Code Online (Sandbox Code Playgroud) 我正在使用http://www.freertos.org/作为应用程序,但我无法找到如何在启动后获得系统时间.我可以创建一个任务并不断更新计数器,但我认为这不是一件好事,因为调度程序可能会安排我的任务(并且提高优先级可能会挂起我的"真实"工作任务).
所以,我想知道什么是最好的解决方案,以获得自系统启动以来经过了多少毫秒.