#5 Switched to use maria database to store song information #7 Added spring and hibernate support #8 Added song upload functionality
75 lines
2.8 KiB
Java
75 lines
2.8 KiB
Java
/**
|
|
*
|
|
* Project: Eight Track, File: AESService.java
|
|
*
|
|
* Copyright 2019-2019 Locusworks LLC.
|
|
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
|
* any means and imposes fines up to $25,000 for violation. No part of this material
|
|
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
|
* modified, duplicated, adapted or translated into another program language in any
|
|
* form or by any means, electronic, mechanical, photocopying, recording, or
|
|
* otherwise, without the prior written permission from Locusworks. Locusworks
|
|
* affirms that Eight-Track(R) software and data is subject to United States
|
|
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
|
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
|
*
|
|
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
|
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
|
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
|
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
|
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
|
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
|
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
|
*/
|
|
package net.locusworks.discord.eighttrack.services;
|
|
|
|
import java.io.IOException;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
import java.nio.file.Paths;
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import net.locusworks.crypto.AES;
|
|
|
|
@Service
|
|
public class AESService {
|
|
private AES aes;
|
|
|
|
@PostConstruct
|
|
private void init() throws IOException {
|
|
Path keyFile = Paths.get("key.bin");
|
|
if (!Files.exists(keyFile)) {
|
|
throw new IOException("Unable to find key.bin in local directory");
|
|
}
|
|
|
|
byte[] key = IOUtils.toByteArray(Files.newInputStream(keyFile));
|
|
|
|
this.aes = AES.createInstance(key);
|
|
}
|
|
|
|
public String encrypt(String plainText) {
|
|
return aes.encrypt(plainText);
|
|
}
|
|
|
|
public String decrypt(String encryptedText) {
|
|
return aes.decrypt(encryptedText);
|
|
}
|
|
|
|
public static void main(String[] args) throws IOException {
|
|
AESService service = new AESService();
|
|
service.init();
|
|
|
|
System.out.println(service.encrypt("zeGAPgbH9HFbqmjRjmwzUDKv"));
|
|
|
|
}
|
|
|
|
}
|