Created
July 14, 2009 16:25
-
-
Save axemclion/147041 to your computer and use it in GitHub Desktop.
ATMOS security API - RSA Smash Challenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.emc.smashup.atmos.api; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.FileOutputStream; | |
import org.apache.commons.codec.binary.Base64; | |
import com.emc.esu.api.DownloadHelper; | |
import com.emc.esu.api.EsuApi; | |
import com.emc.esu.api.Identifier; | |
import com.emc.esu.api.Metadata; | |
import com.emc.esu.api.MetadataList; | |
import com.emc.esu.api.ObjectId; | |
import com.emc.esu.api.ObjectMetadata; | |
import com.emc.smashup.rkm.ClientConfig; | |
import com.rsa.kmc.Decrypter; | |
import com.rsa.kmc.KMConfig; | |
import com.rsa.kmc.KMContext; | |
import com.rsa.kmc.KMKey; | |
import com.rsa.kmc.KeyAlias; | |
public class DownloadDecryptHelper extends DownloadHelper { | |
EsuApi esuApi; | |
public DownloadDecryptHelper(EsuApi esuApi, byte[] buffer) { | |
super(esuApi, buffer); | |
this.esuApi = esuApi; | |
} | |
@Override | |
public void readObject(Identifier id, File f) { | |
super.readObject(id, f); | |
byte b[] = new byte[1024]; | |
try { | |
FileInputStream stream = new FileInputStream(f); | |
stream = new FileInputStream(f); | |
String content = ""; | |
int length = 0; | |
while ((length = stream.read(b)) > 0) { | |
content += new String(b, 0, length); | |
} | |
String decryptedContent = decryptData(content.getBytes()); | |
File file = f.getAbsoluteFile(); | |
FileOutputStream outputStream = new FileOutputStream(file); | |
outputStream.write(decryptedContent.getBytes()); | |
outputStream.close(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
public String decryptData(byte b[]) { | |
String message = ""; | |
try { | |
KMConfig config = new KMConfig(ClientConfig.SAMPLE_CLIENT_KEYSTORE_PASSWORD, | |
ClientConfig.SAMPLE_CACHE_PASSWORD, "config/sample_config.properties"); | |
KMContext kmContext = config.newKMContext(); | |
Decrypter decrypter = kmContext.getDecrypter(); | |
b = Base64.decodeBase64(b); | |
byte[] result = decrypter.doFinal(b, 0, b.length); | |
message = new String(result); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
return message; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment