private String decode( String string ) throws UnsupportedEncodingException { byte[] bytes = Base64.decodeBase64( string ); EncryptionResult result = EncryptionResult.fromByteArray(bytes); byte[] clear = cryptoService.decryptForCluster(clusterName, EncryptUriDescriptor.PASSWORD_ALIAS, result.cipher, result.iv, result.salt); if (clear != null) { return new String(clear, StandardCharsets.UTF_8); } return null; } }
private String encode( String string ) throws UnsupportedEncodingException { EncryptionResult result = cryptoService.encryptForCluster(clusterName, EncryptUriDescriptor.PASSWORD_ALIAS, string.getBytes(StandardCharsets.UTF_8)); string = Base64.encodeBase64URLSafeString(result.toByteAray()); return string; }
@Override public void initializeContribution(DeploymentContext context) { super.initializeContribution(context); crypto.createAndStoreEncryptionKeyForCluster(GATEWAY, ENCRYPT_ACCESS_TOKENS); }
public String getRegistrationCode(String clusterName) { String code = generateRegCode(16); byte[] signature = crypto.sign("SHA256withRSA","gateway-identity",code); String encodedSig = Base64.encodeBase64URLSafeString(signature); return code + "::" + encodedSig; }
boolean verified = crypto.verify("SHA256withRSA", "gateway-identity", parts[0], Base64.decodeBase64(parts[1])); if (verified) { Map<String,RegEntry> clusterServices = registry.get(clusterName);
@Override public String getRegistrationCode(String clusterName) { String code = generateRegCode(16); byte[] signature = crypto.sign("SHA256withRSA","gateway-identity",code); String encodedSig = Base64.encodeBase64URLSafeString(signature); return code + "::" + encodedSig; }
boolean verified = crypto.verify("SHA256withRSA", "gateway-identity", parts[0], Base64.decodeBase64(parts[1])); if (verified) { HashMap<String,RegEntry> clusterServices = registry.get(clusterName);
private String compressEncryptBase64(final Object o) { if (o == null || o.equals("") || (o instanceof Map<?,?> && ((Map<?,?>)o).isEmpty())) { return null; } else { byte[] bytes = javaSerializationHelper.serializeToBytes((Serializable) o); /* compress the data */ try { bytes = compress(bytes); if(bytes.length > 3000) { logger.warn("Cookie too big, it might not be properly set"); } } catch (final IOException e) { throw new TechnicalException(e); } EncryptionResult result = cryptoService.encryptForCluster(this.clusterName, PAC4J_PASSWORD, bytes); return Base64.encodeBase64String(result.toByteAray()); } }
private Serializable uncompressDecryptBase64(final String v) { if (v != null && v.length() > 0) { byte[] bytes = Base64.decodeBase64(v); EncryptionResult result = EncryptionResult.fromByteArray(bytes); byte[] clear = cryptoService.decryptForCluster(this.clusterName, PAC4J_PASSWORD, result.cipher, result.iv, result.salt); if (clear != null) { try { return javaSerializationHelper.unserializeFromBytes(unCompress(clear)); } catch (IOException e) { throw new TechnicalException(e); } } } return null; }
private String compressEncryptBase64(final Object o) { if (o == null || o.equals("") || (o instanceof Map<?,?> && ((Map<?,?>)o).isEmpty())) { return null; } else { byte[] bytes = javaSerializationHelper.serializeToBytes((Serializable) o); /* compress the data */ try { bytes = compress(bytes); if(bytes.length > 3000) { logger.warn("Cookie too big, it might not be properly set"); } } catch (final IOException e) { throw new TechnicalException(e); } EncryptionResult result = cryptoService.encryptForCluster(this.clusterName, PAC4J_PASSWORD, bytes); return Base64.encodeBase64String(result.toByteAray()); } }
private Serializable uncompressDecryptBase64(final String v) { if (v != null && !v.isEmpty()) { byte[] bytes = Base64.decodeBase64(v); EncryptionResult result = EncryptionResult.fromByteArray(bytes); byte[] clear = cryptoService.decryptForCluster(this.clusterName, PAC4J_PASSWORD, result.cipher, result.iv, result.salt); if (clear != null) { try { return javaSerializationHelper.unserializeFromBytes(unCompress(clear)); } catch (IOException e) { throw new TechnicalException(e); } } } return null; }