How to resolve AbstractMethod Error in blob encryption?

95 Views Asked by At

I want to upload blob into azure blob storage by applying encryption for it. so i have tried to do it using following code:

 File f=new File("/home/prospera-user15/Desktop/test/download.jpeg");

        CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionString);
        CloudBlobClient serviceClient = account.createCloudBlobClient();
        // Container name must be lower case.
        CloudBlobContainer container = serviceClient.getContainerReference("upload1");
        container.createIfNotExists();
        CloudBlockBlob blob = container.getBlockBlobReference("megha");
        final KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
        keyGen.initialize(2048);
        final KeyPair wrapKey = keyGen.generateKeyPair();

        RsaKey key = new RsaKey("RSA",wrapKey);
        System.out.println("Uploading the encrypted blob.");
        BlobEncryptionPolicy policy = new BlobEncryptionPolicy(key, null);
        BlobRequestOptions options = new BlobRequestOptions();
        options.setEncryptionPolicy(policy);
        AccessCondition accessCondition = null;
        OperationContext opContext = null;
        try{
            blob.upload(new FileInputStream(f), f.length(), accessCondition, options, opContext);
        }catch (IOException e) {
            System.out.println(e.getMessage());
        }catch (StorageException e) {
            System.out.println(e.getErrorCode());
        }

for above code i got following exception:

2

There are 2 best solutions below

0
Ravi On

AbstractMethodError implies the definition of some class has incompatibly changed since last compilation

In your case, you might be using old version of an interface implementation which is missing a new interface method and as per stacktrace that might be your RsaKey class/interface.

0
Adam Smith - Microsoft Azure On

This exception is thrown when an application tries to call an abstract method. Normally, this error is caught by the compiler; this error can only occur at run time if the definition of some class has incompatibly changed since the currently executing method was last compiled.

Source:https://docs.oracle.com/javase/6/docs/api/java/lang/AbstractMethodError.html

Have you also tried to check if you have authorized your application to use the key or secret per the documentation here ?