org.springframework.security.crypto.codec.Utf8 Java Examples
The following examples show how to use
org.springframework.security.crypto.codec.Utf8.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SignedTokenServiceBackend.java From haven-platform with Apache License 2.0 | 6 votes |
@Override public TokenData createToken(TokenConfiguration config) { final long creationTime = System.currentTimeMillis(); byte[] serverSecret = computeServerSecretApplicableAt(creationTime); byte[] content = contentPack(creationTime, generateRandom(), serverSecret, Utf8.encode(pack(config.getUserName(), config.getDeviceHash()))); byte[] sign = sign(content); ByteBuffer buffer = ByteBuffer.allocate(1 + sign.length + 1 + content.length); store(buffer, content); store(buffer, sign); String key = base32.encodeAsString(buffer.array()); return new TokenDataImpl(creationTime, TokenUtils.getKeyWithTypeAndToken(TYPE, key), config.getUserName(), config.getDeviceHash()); }
Example #2
Source File: SignedTokenServiceBackend.java From haven-platform with Apache License 2.0 | 5 votes |
@Override public TokenData getToken(String tokenString) { final String key = unwrapToken(tokenString); if (key.isEmpty()) { return null; } byte[] decodedKey = base32.decode(key); byte[] currentSignature; final long creationTime; byte[] random; byte[] payload; { byte[] content; { ByteBuffer buffer = ByteBuffer.wrap(decodedKey); content = restoreArray(buffer); currentSignature = restoreArray(buffer); } ByteBuffer contentBuffer = ByteBuffer.wrap(content); creationTime = contentBuffer.getLong(); random = restoreArray(contentBuffer); // we need to skip secret restoreArray(contentBuffer); payload = restoreArray(contentBuffer); } final byte[] serverSecret = computeServerSecretApplicableAt(creationTime); // Verification byte[] expectedSign = sign(contentPack(creationTime, random, serverSecret, payload)); Assert.isTrue(Arrays.equals(expectedSign, currentSignature), "Key verification failure"); String[] unpack = unpack(Utf8.decode(payload)); return new TokenDataImpl(creationTime, TokenUtils.getKeyWithTypeAndToken(TYPE, key), unpack[0], unpack[1]); }
Example #3
Source File: MessageDigestPasswordEncoder.java From lemon with Apache License 2.0 | 5 votes |
public MessageDigestPasswordEncoder(String algorithm, CharSequence secret) { try { messageDigest = MessageDigest.getInstance(algorithm); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException("No such hashing algorithm", e); } this.secret = Utf8.encode(secret); this.saltGenerator = KeyGenerators.secureRandom(); }
Example #4
Source File: AesEncryptor.java From blog with Apache License 2.0 | 4 votes |
public String encrypt(String text) { return new String(Hex.encode(encryptor.encrypt(Utf8.encode(text)))); }
Example #5
Source File: AesEncryptor.java From blog with Apache License 2.0 | 4 votes |
public String decrypt(String encryptedText) { return Utf8.decode(encryptor.decrypt(Hex.decode(encryptedText))); }
Example #6
Source File: SignedTokenServiceBackend.java From haven-platform with Apache License 2.0 | 4 votes |
private byte[] computeServerSecretApplicableAt(long time) { return Utf8.encode(serverSecret + ":" + (time % serverInteger)); }
Example #7
Source File: VaultBytesEncryptor.java From spring-vault with Apache License 2.0 | 3 votes |
@Override public byte[] encrypt(byte[] plaintext) { Assert.notNull(plaintext, "Plaintext must not be null"); Assert.isTrue(!ObjectUtils.isEmpty(plaintext), "Plaintext must not be empty"); Ciphertext ciphertext = this.transitOperations.encrypt(this.keyName, Plaintext.of(plaintext)); return Utf8.encode(ciphertext.getCiphertext()); }
Example #8
Source File: VaultBytesEncryptor.java From spring-vault with Apache License 2.0 | 3 votes |
@Override public byte[] decrypt(byte[] ciphertext) { Assert.notNull(ciphertext, "Ciphertext must not be null"); Assert.isTrue(!ObjectUtils.isEmpty(ciphertext), "Ciphertext must not be empty"); Plaintext plaintext = this.transitOperations.decrypt(this.keyName, Ciphertext.of(Utf8.decode(ciphertext))); return plaintext.getPlaintext(); }
Example #9
Source File: Base64EncodingTextEncryptor.java From flair-engine with Apache License 2.0 | 2 votes |
/** * Encrypt the raw text string. * * @param text text */ @Override public String encrypt(String text) { return Base64.toBase64String(bytesEncryptor.encrypt(Utf8.encode(text))); }
Example #10
Source File: Base64EncodingTextEncryptor.java From flair-engine with Apache License 2.0 | 2 votes |
/** * Decrypt the encrypted text string. * * @param encryptedText text */ @Override public String decrypt(String encryptedText) { return Utf8.decode(bytesEncryptor.decrypt(Base64.decode(encryptedText))); }