Esta página ainda não está disponível no idioma selecionado. Estamos trabalhando para adicionar mais opções de idiomas. Agradecemos sua compreensão.
- Service Overview
- Billing
- Getting Started
-
User Guide
- Before You Start
- Buying an Instance
- Instance Management
-
Enterprise Administrator Guide
- Logging In to the OneAccess Administrator Portal
- User Management
-
Resources
- Overview
-
Applications
- Adding an Application
- Enabling, Disabling, or Deleting an Application
- General Information
- Authentication Integration
- Synchronization Integration
- Login Configuration
- Access Control
- Object Models
- Authorization Management
- API Permission Management
- Application Permission Management
- Security Settings
- Audit Logs
- APIs
- Authentication
- Security
- Audit
- Settings
- Common User Guide
- Key Operations Recorded by CTS
-
Best Practices
- OneAccess Best Practices
- Identity Source Integration
-
Application Integration
-
Logging In to the Huawei Cloud Through User Portal
- Introduction
- Logging In to Single Huawei Cloud Account via OneAccess Without Password (SAML - Virtual User SSO)
- Logging In to Multiple Huawei Cloud Accounts via OneAccess Without Password (SAML - Virtual User SSO)
- Logging In to Single Huawei Cloud Account via OneAccess Without Password (SAML - IAM User SSO)
- Logging In to Multiple Huawei Cloud Accounts via OneAccess Without Password (SAML - IAM User SSO)
- Logging In to Huawei Cloud via OneAccess Without Password (OIDC)
- SSO Access to Applications Through SAML
- SSO Access to Applications Through OAuth 2.0
- SSO Access to Applications Through OIDC
- SSO Access to Applications Through CAS
- SSO Access to Applications Through Plug-in Autocompletion
-
Logging In to the Huawei Cloud Through User Portal
- Data Synchronization
- Authentication Provider Integration
- Authorizing IAM Users to Access a OneAccess Instance Administrator Portal
- API Usage
- Configuring MFA for User Login
- Developer Guide
-
API Reference
- Before You Start
- API Overview
-
OneAccess APIs
-
Management APIs
- Calling APIs
- Access Credentials
-
User Management
- Creating a User
- Modifying a User
- Deleting a User
- Enabling a User
- Disabling a User
- Changing a User Password
- Verifying and Modifying the Original User Password
- Querying User Details by User ID
- Querying User Details by Username
- Querying the User List
- Authorizing an Application Account
- Querying All Authorized Application Accounts of a User
- Organization Management
- Application Organization Management
- Application Account Management
- Application Role Management
- User APIs
- Application Integration APIs
-
Management APIs
- Appendix
- FAQs
- General Reference
Copied.
Signing a Session Token
Signing Process
- Construct the data to be signed: "session_token="+sessionToken+"×tamp="+timestamp+"&nonce="+nonce.
In the data, timestamp indicates the timestamp of the current server. The timestamp can be obtained by calling the API used to obtain the server timestamp. nonce is a random character string generated for each signature. The string can be a hexadecimal string of the current timestamp.
- Obtain a public key by calling the corresponding API.
The signature algorithm is RSA, and the padding mode is RSA/ECB/OAEPWithSHA-256AndMGF1Padding. The encrypted data to be signed must be encoded using Base64.
Java Code Signing Example
import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.apache.commons.codec.binary.Base64; import javax.crypto.Cipher; import java.nio.charset.Charset; import java.security.*; import java.security.spec.InvalidKeySpecException; import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; import java.util.Date; public class RSAUtils { public static final Provider provider = new BouncyCastleProvider(); public static final String KEY_ALGORITHM = "RSA"; public static final String BEGIN_PRI_KEY = "-----BEGIN RSA PRIVATE KEY-----"; public static final String END_PRI_KEY = "-----END RSA PRIVATE KEY-----"; public static final String BEGIN_PUB_KEY = "-----BEGIN PUBLIC KEY-----"; public static final String END_PUB_KEY = "-----END PUBLIC KEY-----"; // Encryption public static String encrypt(String input, String publicKey) { // Remove the start and end identifiers and newline characters from the public key. publicKey = publicKey.replaceAll(BEGIN_PUB_KEY, "").replaceAll(END_PUB_KEY, "").replace("\\n", ""); try { byte[] enStrByte = encrypt(input, getPublicRSAKey(publicKey)); return Base64Utils.encodeToString(enStrByte); }catch (Exception e){ throw new RuntimeException("Could not encrypt data ",e); } } private static PublicKey getPublicRSAKey(String key) throws NoSuchAlgorithmException, InvalidKeySpecException { X509EncodedKeySpec x509 = new X509EncodedKeySpec(Base64Utils.decodeFromString(key)); KeyFactory kf = KeyFactory.getInstance(KEY_ALGORITHM, provider); return kf.generatePublic(x509); } private static byte[] encrypt(String input, PublicKey publicKey) throws Exception { Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding", provider); cipher.init(Cipher.ENCRYPT_MODE, publicKey); byte[] re = cipher.doFinal(input.getBytes("UTF-8")); return re; } // Decryption public String decrypt(String input, String privateKey) { privateKey = privateKey.replaceAll(BEGIN_PRI_KEY, "").replaceAll(END_PRI_KEY, "").replace("\\n", ""); try { byte[] bt = Base64.decodeBase64(input); byte[] decryptedData = RSAUtils.decrypt(bt, RSAUtils.getPrivateRSAKey(privateKey)); return validateData(decryptedData); }catch (Exception e){ return e.getMessage(); } } private static byte[] decrypt(byte[] encrypted, PrivateKey privateKey) throws Exception { Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding", provider); cipher.init(Cipher.DECRYPT_MODE, privateKey); return cipher.doFinal(encrypted); } public static PrivateKey getPrivateRSAKey(String key) throws InvalidKeySpecException, NoSuchAlgorithmException { PKCS8EncodedKeySpec pkcs8 = new PKCS8EncodedKeySpec(Base64Utils.decodeFromString(key)); KeyFactory kf = KeyFactory.getInstance(KEY_ALGORITHM, provider); return kf.generatePrivate(pkcs8); } private static String validateData(byte[] decryptedData) { String dataStr = new String(decryptedData, Charset.defaultCharset()); if (dataStr!=null && dataStr.length() > 0){ String[] split = dataStr.split("#"); if (split.length > 1 && split[split.length-1].length() == String.valueOf(new Date().getTime()).length()) { try { if (new Date().getTime() - Long.parseLong(split[split.length-1]) < 5*60*1000L){ return dataStr.substring(0,dataStr.length()-1-split[split.length-1].length()); }else { throw new RuntimeException("operate time out"); } } catch (Exception e) { throw new RuntimeException("wrong timestamp ", e); } }else { return dataStr; } } return null; } }
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot