Bu sayfa henüz yerel dilinizde mevcut değildir. Daha fazla dil seçeneği eklemek için yoğun bir şekilde çalışıyoruz. Desteğiniz için teşekkür ederiz.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

RSAUtils

Updated on 2023-02-28 GMT+08:00

Path

com.roma.apic.livedata.common.v1.RSAUtils

Description

This class is used to provide the RSA encryption and decryption methods.

Example

Use the following Java code to generate a public key and a private key:

import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.Base64;

public class Main {

    public static void main(String[] args) {
        try {
            KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
            keyPairGenerator.initialize(1024);
            KeyPair keyPair = keyPairGenerator.generateKeyPair();
            PublicKey publicKey = keyPair.getPublic();
            System.out.println("publicKey:" + new String(Base64.getEncoder().encode(publicKey.getEncoded())));

            PrivateKey privateKey = keyPair.getPrivate();
            System.out.println("privateKey:" + new String(Base64.getEncoder().encode(privateKey.getEncoded())));
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }
    }
}

Add the public key and private key to the following code:

importClass(com.roma.apic.livedata.common.v1.RSAUtils);
importClass(com.roma.apic.livedata.common.v1.Base64Utils);

function execute(data) {
    var publicKeyString = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDd4CRRppmYVlFl3dX4iVGN+2Twy5gLeEPRbvhOko/xFipGF7XV0weTp4wCakgdnm+DR4gBBrQtfAuKwYIBPIr+C1FI5sKYA3NxazDWUcXR3xlPM5D0DWjacjcMjnaj2v21WZxGpwHZHQ9TLd4OBBq3fva1r/cE8s1Lji5QeFiklwIDAQAB";

    var privateKeyString = "**********";

    var publicKey = RSAUtils.getPublicKey(publicKeyString)
    var privateKey = RSAUtils.getPrivateKey(privateKeyString)

    var origin = "hello rsa"
    var encrypted = RSAUtils.encrypt(Base64Utils.encode(origin), publicKey)

    var decrypted = RSAUtils.decrypt(encrypted, privateKey)
    return decrypted
}

Constructor Details

public RSAUtils()

Constructs an RSAUtils class without parameters.

Method List

Returned Type

Method and Description

static byte[]

decodeBase64(String base64)

Decode a Base64 character string to binary data.

static byte[]

decrypt(java.security.PrivateKey privateKey, byte[] encryptData)

Decrypt data using the RSA algorithm.

static String

decrypt(String source, java.security.interfaces.RSAPrivateKey privateKey)

Decrypt data using the RSA algorithm (the source is encoded using Base64).

static String

decrypt(String source, java.security.interfaces.RSAPrivateKey privateKey, Map<String, String> config)

Decrypt data using the RSA algorithm (the source is encoded using Base64).

static String

decrypt(byte[] source, java.security.interfaces.RSAPrivateKey privateKey)

Decrypt data using the RSA algorithm.

static String

decrypt(byte[] source, java.security.interfaces.RSAPrivateKey privateKey, Map<String, String> config)

Decrypt data using the RSA algorithm.

static String

encodeBase64(byte[] bytes)

Encode binary data to a Base64 character string.

static byte[]

encrypt(java.security.PublicKey publicKey, byte[] source)

Encrypt data using the RSA algorithm.

static String

encrypt(String source, java.security.PublicKey publicKey)

Encrypt data using the RSA algorithm (both the source and returned data is encoded using Base64).

static String

encrypt(String source, java.security.PublicKey publicKey, Map<String, String> config)

Encrypt data using the RSA algorithm (both the source and returned data is encoded using Base64).

static String

encrypt(byte[] source, java.security.PublicKey publicKey)

Encrypt data using the RSA algorithm (the returned data is encoded using Base64).

static String

encrypt(byte[] source, java.security.PublicKey publicKey, Map<String, String> config)

Encrypt data using the RSA algorithm (the returned data is encoded using Base64).

static java.security.interfaces.RSAPrivateKey

getPrivateKey(byte[] privateKeyByte)

Create an RSA private key by using a private key byte array.

static java.security.interfaces.RSAPrivateKey

getPrivateKey(String privateKeyByte)

Create an RSA private key by using a Base64-encoded private key.

static java.security.interfaces.RSAPrivateKey

getPrivateKey(String modulus, String exponent)

Create an RSA private key by using the modulus and exponent.

static java.security.interfaces.RSAPublicKey

getPublicKey(byte[] publicKeyByte)

Create an RSA public key by using a public key byte array.

static java.security.interfaces.RSAPublicKey

getPublicKey(String publicKeyByte)

Create an RSA public key by using a Base64-encoded public key.

static java.security.PublicKey

getPublicKey(String modulus, String exponent)

Create an RSA public key by using the modulus and exponent.

Method Details

  • public static byte[] decodeBase64(String base64)

    Decode a Base64 character string to binary data.

    Input Parameter

    base64 indicates the data encoded using Base64.

    Returns

    Data decoded by using Base64

  • public static byte[] decrypt(java.security.PrivateKey privateKey, byte[] encryptData)

    Decrypt data using the RSA algorithm.

    Input Parameter

    • privateKey indicates a private key.
    • encryptData indicates the data to be decrypted.

    Returns

    Decrypted data.

  • public static String decrypt(String source, java.security.interfaces.RSAPrivateKey privateKey)

    Decrypt data using the RSA algorithm.

    Input Parameter

    • source indicates the Base64 code of the data to be decrypted.
    • privateKey indicates a private key.

    Returns

    Decrypted data.

  • public static String decrypt(String source, java.security.interfaces.RSAPrivateKey privateKey, Map<String,String>config)

    Decrypt data using the RSA algorithm.

    Input Parameter

    • source indicates the Base64 code of the data to be decrypted.
    • privateKey indicates a private key.
    • config indicates the decryption configuration. The options are as follows:

      transformation: specifies the decryption algorithm/mode/padding, for example, RSA/ECB/OAEPPadding. For details, see the parameter description.

    Returns

    Decrypted data.

  • public static String decrypt(byte[] source, java.security.interfaces.RSAPrivateKey privateKey)

    Decrypt data using the RSA algorithm.

    Input Parameter

    • source indicates data to be decrypted.
    • privateKey indicates a private key.

    Returns

    Decrypted data.

  • public static String decrypt(byte[] source, java.security.interfaces.RSAPrivateKey privateKey, Map<String,String>config)

    Decrypt data using the RSA algorithm.

    Input Parameter

    • source indicates data to be decrypted.
    • privateKey indicates a private key.
    • config indicates the decryption configuration. The options are as follows:

      transformation: specifies the decryption algorithm/mode/padding, for example, RSA/ECB/OAEPPadding. For details, see the parameter description.

    Returns

    Decrypted data.

  • public static String encodeBase64(byte[] bytes)

    Encode binary data to a Base64 character string.

    Input Parameter

    bytes indicates data to be encoded.

    Returns

    Base64 encoding.

  • public static byte[] encrypt(java.security.PublicKey publicKey, byte[] source)

    Encrypt data using the RSA algorithm.

    Input Parameter

    • publicKey indicates a public key.
    • source indicates the content to be encrypted.

    Returns

    Encrypted data content.

  • public static String encrypt(String source, java.security.PublicKey publicKey)

    Encrypt data using the RSA algorithm.

    Input Parameter

    • source indicates the Base64 code of the data to be encrypted.
    • publicKey indicates a public key.

    Returns

    Base64 code of the encrypted data content.

  • public static String encrypt(String source, java.security.PublicKey publicKey, Map<String, String> config)

    Encrypt data using the RSA algorithm.

    Input Parameter

    • source indicates the Base64 code of the data to be encrypted.
    • publicKey indicates a public key.
    • config indicates the encryption option. The options are as follows:

      transformation: specifies the encryption algorithm/mode/padding, for example, RSA/ECB/OAEPPadding. For details, see the parameter description.

  • public static String encrypt(byte[] source, java.security.PublicKey publicKey)

    Encrypt data using the RSA algorithm.

    Input Parameter

    • source indicates the content to be encrypted.
    • publicKey indicates a public key.

    Returns

    Base64 code of the encrypted data content.

  • public static String encrypt(byte[] source, java.security.PublicKey publicKey, Map<String, String> config)

    Encrypt data using the RSA algorithm.

    Input Parameter

    • source indicates the content to be encrypted.
    • publicKey indicates a public key.
    • config indicates the encryption option. The options are as follows:

      transformation: specifies the encryption algorithm/mode/padding, for example, RSA/ECB/OAEPPadding. For details, see the parameter description.

    Returns

    Base64 code of the encrypted data content.

  • public static java.security.interfaces.RSAPrivateKey getPrivateKey(byte[] privateKeyByte)

    Create an RSA private key by using the private key of the x509 format.

    Input Parameter

    privateKeyByte indicates the private key encoded in x509 format

    Returns

    Private key.

  • public static java.security.interfaces.RSAPrivateKey getPrivateKey(String privateKeyByte)

    Create an RSA private key by using the private key of the x509 format.

    Input Parameter

    privateKeyByte indicates the private key encoded in x509 format

    Returns

    Private key.

  • public static java.security.interfaces.RSAPrivateKey getPrivateKey(String modulus, String exponent)

    Create an RSA private key by using the modulus and exponent.

    Input Parameter

    • modulus indicates the modulus required for generating a private key.
    • exponent indicates the exponent required for generating a private key.

    Returns

    RSA private key.

  • public static java.security.interfaces.RSAPublicKey getPublicKey(byte[] publicKeyByte)

    Create an RSA public key by using a public key encoded in x509 format.

    Input Parameter

    publicKeyByte indicates the public key encoded in x509 format.

    Returns

    Public key.

  • public static java.security.PublicKey getPublicKey(String modulus, String exponent)

    Create an RSA public key by using the modulus and exponent.

    Input Parameter

    • modulus indicates the modulus required for generating a public key.
    • exponent indicates the exponent required for generating a public key.

    Returns

    RSA public key.

Sitemizi ve deneyiminizi iyileştirmek için çerezleri kullanırız. Sitemizde tarama yapmaya devam ederek çerez politikamızı kabul etmiş olursunuz. Daha fazla bilgi edinin

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback